The Artima Developer Community
Sponsored Link

Java Answers Forum
Connect mySQL by using JDBC in linux

2 replies on 1 page. Most recent reply: Dec 23, 2002 3:22 AM by stupidstudent

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
stupidstudent

Posts: 3
Nickname: stupidstud
Registered: Dec, 2002

Connect mySQL by using JDBC in linux Posted: Dec 22, 2002 2:38 AM
Reply to this message Reply
Advertisement
hi,

i don't why i cannot connect the database

i put the mysql-connection-java-2.0.14-bin-jar in tomcat
>classes>lib

i try
Class.forName("org.gjt.mm.mysql.Driver").newInstance();or Class.forName("com.mysql.jdbc.Driver").newInstance();

con=DriverManager.getConnection("jdbc:mysql://localhost/test");

as i have not set the password for the database

what can i do to connect to database
thanks a lot

regard
pig


Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: Connect mySQL by using JDBC in linux Posted: Dec 22, 2002 6:20 PM
Reply to this message Reply
Heres my 2 cents worth:

1. You need to include your jar file when compiling your classes this way: javac -classpath c:\path\to\mysql-connection-java-2.0.14-bin-jar YourClass.java I suggest you test write there in your work folder. Put your code in a try block and check for messages. After you think its OK, move your servlet to Tomcat.
try
{
	//...sql code	
}
catch(ClassNotFoundException cnfe)
{
	cnfe.printStackTrace();
}
catch(SQLException sqle)
{
	System.err.println("Error Code:" + sqle.getErrorCode());
	System.err.println("SQL State:" + sqle.getSQLState());
	sqle.printStackTrace();
}
catch(Exception e)
{
	e.printStackTrace();
}


2. Put your class file in classes folder. But plcae your jar file in $TOMCAT_HOME/lib i.e, the lib directory used by all applications.

Hope that helps.

-Jay

stupidstudent

Posts: 3
Nickname: stupidstud
Registered: Dec, 2002

Re: Connect mySQL by using JDBC in linux Posted: Dec 23, 2002 3:22 AM
Reply to this message Reply
Hi,
Thanks Jay.
After i correct the syntax errors in my program.
I can connect to mySQL by using JDBC now.

regards
pig

Flat View: This topic has 2 replies on 1 page
Topic: How to write an client applet using servlet , through tomcat Previous Topic   Next Topic Topic: Integer Input Methods

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use