on 03-05-2008 3:22 PM
Hi, Im following this blog https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5892. [original link is broken] The only change I did is connection method since I couldnt use same as in the blog. Code from NW pov is clear, I think that photo uploading which I took after "Donwloading and Uploading Files" tutorial works fine. After deploying, uploading the photo and pressing "save" button I get " java.lang.NullPointerException ". No, if we assume that there is uploaded photo in "Resource" context what can couse that error? Ill be gratefull for every idea/suggestion. Regards, Balmer.
try {
{
String userName = "user";
String password = "pswd";
String url = "jdbc:mysql://dbadress";
Class.forName ("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
//Context ctx = new InitialContext();
//DataSource ds = (DataSource) ctx.lookup("jdbc/dataSourceName");
//Connection con=ds.getConnection();
Statement st=con.createStatement();
PreparedStatement pSt=con.prepareStatement( "insert into photo values(?)");
IWDResource res=wdContext.currentContextElement().getResource() ;
InputStream in = res.read(false);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int length;
byte[] part = new byte[10 * 1024];
while ((length = in.read(part)) != -1) {
bOut.write(part, 0, length);
}
in.close();
pSt.setBytes( 1,bOut.toByteArray());
pSt.execute() ;
bOut.close();
wdComponentAPI .getMessageManager().reportSuccess("sukces");
}
catch(Exception e)
{
wdComponentAPI.getMessageManager() .reportWarning( e.toString() );
}
Hi Balmer,
Use Following code to register your driver.
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
Then call the connection and write proper connection string.
Regards.
Deepak
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Balmer,
Where are u getting Null Pointer Error?
While connecting to DataBase or while executing the statement??
-
Shyam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I hash writing photo into db part of code theres no NullPointer error, but no "Database connection established" as well. So I really dont know if it is connected or not. Unhashing writing part generates Nullpointer error however that part of code is copied from blog so I dont thing it doesnt work properly. Only thing I changed slightly comparing to blog is connection. Thanks for answers, Balmer.
Hi,
try only with this code.. So that u can figure out whether problem in Database connection or not.
try {
String userName = "user";
String password = "pswd";
String url = "jdbc:mysql://dbadress";
Class.forName ("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection (url, userName, password);
wdComponentAPI.getMessageManager() .reportSuccess
("Database connection established");
} catch(Exception e) {
wdComponentAPI.getMessageManager() .reportWarning( e.toString() );
}
-
Shyam.
Thank you Shyam for answers, I really appreciate it. That last piece of code didnt change a thing. Still those two messages appear, no picture was written. Something must be wrong, problem is that it comes from blog and it should work but it doesnt and that makes me worried... Not much ideas left.
Do you by any chance have working tutorial or example project or whatever that shows how things (strings from inputfields, strings from DropBoxes, booleans from checkboxes etc) are written into MySQL database? Enything that will lighten up the issue. Regards, Balmer
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.