Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,074 members, 7,957,002 topics. Date: Tuesday, 24 September 2024 at 03:03 AM |
Nairaland Forum / Science/Technology / Programming / HELP On Connecting Netbeans To A Database (1214 Views)
Is Anything Better Than The Netbeans Ide? / Netbeans Vs Eclipse Vs Jboss / Connecting To A Database Using Visual Basic (2) (3) (4)
HELP On Connecting Netbeans To A Database by koderNeptune(m): 8:16pm On Nov 25, 2013 |
I am currently working on an application, and i need to store inputs into the database. I need your need fellow Java programmers. Please give help between MySQL and the embedded database (glassfish). I connected my application to the embedded database and created my database and tables nicely, but whenever click on the send or store button, it gives an error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) nd like dt. Or is it where i place the code that is not working?, but i think the code should be on the send button. Expecting your HELP.... |
Re: HELP On Connecting Netbeans To A Database by codeaddict(m): 8:54pm On Nov 25, 2013 |
Have you added mysql connector/j to your build path? |
Re: HELP On Connecting Netbeans To A Database by Danyl(m): 9:02pm On Nov 25, 2013 |
there could be a lot of reasons for that but in your own case I will ask you the following just answer them so as to knw where you got it missing. 1. are u developing a desktop gui app or a web application. 2. why did u choosing mysql though there is no stable embedded mysql database wrapper you cn use to create embedded mysql db but there are better alternatives which are java derby, SQLITE, n a host of odas. 3. what source code hv u tried which is not working though I doubt it if u have any. 4. ClassNotFoundException is indicative of d fact dat d external library dat contains ur mysql driver is missing from the class path n its has not been included in d project properties... so answer those questions when you r free.... I might as well suggest u use ORM frameworks like Oracle toplinks but u might b ready for that but your answers to the above questions will go along way. |
Re: HELP On Connecting Netbeans To A Database by koderNeptune(m): 9:37pm On Nov 25, 2013 |
@codeaddict, i have done that. @danyl, I am working a desktop gui app. I have tried java derby before that was y i switched to MySQL, but I think the error has changed to com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''FirstName','LastName','Sex','Qualification','AreaOfSpecialisation','UserId' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) blablahblah so i guess it is the code problem now static final String db_driver = "com.mysql.jdbc.Driver"; static final String db_url = "jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull"; static final String Username = "username"; static final String Password = "password"; Connection con = null; Statement stmt = null; try{ Class.forName("com.mysql.jdbc.Driver" con = DriverManager.getConnection(db_url,Username,Password); stmt = con.createStatement(); String sql = "INSERT Information"+"VALUES('FirstName','LastName','Sex','Qualification','AreaOfSpecialisation','UserId','Password'," + "'Salary','address','NextOfKin','mail','PhoneNumber','DateEmployed)"; stmt.executeUpdate(sql); }catch(SQLException se){ se.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(stmt != null) { con.close(); } }catch(SQLException e){ e.printStackTrace(); } }try{ if(con != null) con.close(); }catch(SQLException e){ e.printStackTrace(); } I hope u re not bored with this. this codes were place behind the save button. |
Re: HELP On Connecting Netbeans To A Database by 0yewale(m): 2:16am On Nov 26, 2013 |
one quote ' is missing at the end of dateEmployed variable @danyl, I am working a desktop gui app. I have tried java derby before that was y i switched to MySQL, but I think the error has changed to com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''FirstName','LastName','Sex','Qualification','AreaOfSpecialisation','UserId' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) blablahblah so i guess it is the code problem now static final String db_driver = "com.mysql.jdbc.Driver"; static final String db_url = "jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull"; static final String Username = "username"; static final String Password = "password"; Connection con = null; Statement stmt = null; try{ Class.forName("com.mysql.jdbc.Driver" con = DriverManager.getConnection(db_url,Username,Password); stmt = con.createStatement(); String sql = "INSERT Information"+"VALUES('FirstName','LastName','Sex','Qualification','AreaOfSpecialisation','UserId','Password'," + "'Salary','address','NextOfKin','mail','PhoneNumber', stmt.executeUpdate(sql); }catch(SQLException se){ se.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(stmt != null) { con.close(); } }catch(SQLException e){ e.printStackTrace(); } }try{ if(con != null) con.close(); }catch(SQLException e){ e.printStackTrace(); } I hope u re not bored with this. this codes were place behind the save button. [/quote] |
Re: HELP On Connecting Netbeans To A Database by Danyl(m): 6:34am On Nov 26, 2013 |
in your query string where you have 'Information' dats where I cn spot a problem. change.your query statement to d ff: String query="INSERT into mytable values"+"('insert d values with comma'); I will suggest u use prepareStatement interface instead of Statement cos Statement 'interface is not as dynamic as prepareStatement at run time so also u cn specify your values dynamically at run time with prepareStatement objects. so also a quote is missing as oyewale mentioned above. |
Re: HELP On Connecting Netbeans To A Database by jboy01(m): 6:47am On Nov 26, 2013 |
0yewale: one quote ' is missing at the end of dateEmployed variable String sql = "INSERT INTO Information"+"VALUES('FirstName','LastName','Sex','Qualification','AreaOfSpecialisation','UserId','Password'," |
Re: HELP On Connecting Netbeans To A Database by Danyl(m): 9:44am On Nov 26, 2013 |
but information was not even specified in d dburl. |
Re: HELP On Connecting Netbeans To A Database by koderNeptune(m): 12:51pm On Nov 26, 2013 |
But, I want to be sure, wen I connected my mysql driver, it loaded all d database I have been working on in my xampp server. I'm I right sha.... |
Re: HELP On Connecting Netbeans To A Database by Danyl(m): 7:54pm On Nov 26, 2013 |
koder_Neptune: But, I want to be sure, wen I connected my mysql driver, it loaded all d database I have been working on in my xampp server.mysql is well fitting for web apps but for desktop u better go for embedded databases except u r doing web apps in java n its a distributed application else u might b wasting time.,derby n H2. or sqlite will do this well for u. |
Re: HELP On Connecting Netbeans To A Database by javadoctor(m): 7:25am On Nov 29, 2013 |
Dis is a driver issue, if u re using mysql,add mysql jconnector.jar to the library project,if u re using java derby,add derby.jar to the project |
Re: HELP On Connecting Netbeans To A Database by koderNeptune(m): 8:06am On Nov 29, 2013 |
I have solved those errors. The ones are facing now is, anytime I try to save and there is space in the jtextfield, like a field asking for name and u input "rice dodo" the error will point to dodo, wen I try to do it again without space in the fields it gave an EOF error. Can you please help me out? Javadoctor and everyone? |
(1) (Reply)
Programmers Psychological Advice Needed Plz / Learning Programming With High Cost Of Internet Bandwidth / I Can't Get A Siwes/it Placement....any Help Please??
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 28 |