Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Null userid is not supported

Status
Not open for further replies.

sudhakarpothu

Programmer
Jan 8, 2007
19
DE
Hi,

I get the following error when i run my Java program to connect DB2 V 9 express Edition database on VMware windowsXP.

com.ibm.db2.jcc.c.SqlException: [ibm][db2][jcc][t4][10205][11234] Null userid is not supported.
at com.ibm.db2.jcc.b.b.E(b.java:1792)
at com.ibm.db2.jcc.b.b.d(b.java:1799)
at com.ibm.db2.jcc.b.b.b(b.java:606)
at com.ibm.db2.jcc.b.b.a(b.java:593)
at com.ibm.db2.jcc.b.b.<init>(b.java:263)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:1 63)
at java.sql.DriverManager.getConnection(DriverManager .java:582)
at java.sql.DriverManager.getConnection(DriverManager .java:207)
at utils.Conn.getConn(Conn.java:30)
at IO.Save.insertFile(Save.java:34)
at IO.Save.main(Save.java:62)
java.lang.NullPointerException
at IO.Save.insertFile(Save.java:40)
at IO.Save.main(Save.java:62)

code:

Conn.java


Code:

package utils;

/**
*
* @author pothu
*/

import java.sql.*;

public class Conn {

// for simplicity, I've hard-coded account and URL data.
private static String user = "administrator";
private static String pwd = "adminadmin";
private static String url = "jdbc:db2:net:172.17.2.197:50000/TDRepos";

// this method gets a database connection
public static Connection getConn(){
Connection conn=null;

// load the appropriate DB2 driver and
// get a connection to the “test” database
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
conn = DriverManager.getConnection(url, user, pwd);

}
catch (Exception e) { e.printStackTrace(); }
return conn;

} // end getConn();

// this method closes a database connection
public static void closeConn(Connection conn){
try {
if(conn == null) { return; }
conn.close();
}
catch (Exception e) { e.printStackTrace(); }
finally {
try { conn.close(); }
catch (Exception e) { }
}
} // end closeConn();
} // end class Save.java


Save.java

Code:


package IO;

/**
*
* @author pothu
*/

import java.io.File;
import java.io.FileInputStream;

import java.sql.Connection;
import java.sql.PreparedStatement;

import utils.Conn;



public class Save {

public static void insertFile(){
try {
// for simplicity, I've defined variables with input data
String projectId = "TDRepo";
java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime());
String log = "D:/TestDataRepository/TDRepo/DataFiles/Log.xml"; // input Log file
String report = "D:/TestDataRepository/TDRepo/DataFiles/Report.xml"; // input Report file

//get a connection
Connection conn = Conn.getConn();

//define string that will insert files without validation
String query = "insert into TESTDATA (PROJECTID, TIMESTAMP, LOGFILE, REPORTFILE) values (?, ?, ? ,?)";

// prepare the statement
PreparedStatement insertStmt = conn.prepareStatement(query);
insertStmt.setString(1, projectId);
insertStmt.setTimestamp(2, sqlDate);
File LOG = new File(log);
insertStmt.setBinaryStream(3, new FileInputStream(LOG), (int)LOG.length());
File REPORT = new File(report);
insertStmt.setBinaryStream(4, new FileInputStream(REPORT), (int)REPORT.length());

//insertStmt.executeUpdate();

//execute the statement
if (insertStmt.executeUpdate() != 1) {
System.out.println("No record inserted.");
}else{System.out.println("Record inserted.");}
//. . .
conn.close();
}
catch (Exception e) {e.printStackTrace(); /*. . .*/ }
}

public static void main(String[] args) {

insertFile();

}
}
I will appreciate help

thanks in advance

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top