MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 24th, 2004, 06:40 AM
Talar's Avatar
Talar Talar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Sweden
Posts: 3 Talar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Using java to connect to a mysql database

I'm having problem connecting to a mysql database using java. Anyone here who knows this stuff and could give me some help?

I'm using mysql to run a local sql server on my machine (win xp). No password is required for connection and connecting to it locally from the command prompt works like a dance.

But I can't connect to it using java and I'm not sure if the fault is with my code or with the installation of the MySQL ConnectorJ driver. I have been reading tons of documentation about the driver and the mysql server, but I can't find any clear instructions on how to install it other than putting the jar file in the java classpath which is what I have done.


The code used for the connection looks like this:

Code:
import java.sql.*;
 import javax.swing.*;
 
 public class javasql{
 public static void main(String[] args) {
 try{
 Class.forName("com.mysql.jdbc.Driver");
 }catch(Exception e){
 e.printStackTrace();
 }
 try{
 Connection c =
 DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?user=Someone");
 c.close();
 }catch (SQLException e){
 e.printStackTrace();
 }
 
 Statement stmt = null; 
 ResultSet rs = null;
 
 try {
 	if (stmt.execute("SELECT name FROM test")) { //this is row 38
 		rs = stmt.getResultSet();
 }
 } 
 		catch(Exception e){
 e.printStackTrace();
 }


And the error message I receive is:

Quote:
java.lang.NullPointerException
at javasql.main(javasql.java:38)

Btw, I use the NetBeans IDE 3.5.1 editor.

Reply With Quote
  #2  
Old March 24th, 2004, 09:49 AM
Talar's Avatar
Talar Talar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Sweden
Posts: 3 Talar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Got it working now after changing the code some

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Using java to connect to a mysql database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway