Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java - Mysql connectivity

 
Amit Goel
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do i connect to mysql database using java servlets . i want to use JdbcOdbcDriver..
i have written the following code which does not work .
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url);
String command="INSERT INTO RegistrationInfo VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement stmt=con.prepareStatement(command);
stmt.setString(1,loginId);
stmt.setString(2,password);
stmt.setLong(3,customerId);
stmt.setString(4,adminName);
stmt.setString(5,orgName);
stmt.setString(6,address1);
stmt.setString(7,address2);
stmt.setString(8,city);
stmt.setString(9,state);
stmt.setString(10,country);
stmt.setInt(11,zipcode);
stmt.setInt(12,phone1);
stmt.setInt(13,phone2);
stmt.setInt(14,fax);
stmt.setString(15,website);
stmt.executeUpdate();
}catch(Exception e) {
e.printStackTrace();
}
please help me .. ireally need it fast
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amit
Are you getting an Exception? Which one?
What is the url you're using in your connection string?
Is the driver in you path?
If your using the JDBCODBC bridge then you alos need to have a DSN set up through myODBC, do you have my ODBC set up?
If you want to just connect with out using the DSN then you'll need a different driver. I've used the mm.mysql.jdbc-1.2c.
hope that helps, if not post some more info about your problem.
[ January 30, 2002: Message edited by: Dave Vick ]
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,can I delete mm.mysql.jdbc-1.2c.bin in jdk1.X after I compiled the jdbc connection Servlet? I tried it and the Servlet seems continue to work too
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic