User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 373,936 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,859 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting

How to Connect MySQL from JSP Page

Join Date: Sep 2006
Posts: 17
Reputation: Dhruv Shah is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Dhruv Shah Dhruv Shah is offline Offline
Newbie Poster

Help How to Connect MySQL from JSP Page

  #1  
Feb 17th, 2007
As I am new to MySQL, I dont know how to connect my jsp page to the MySQL Database.
So please help me by giving some code on how to connect.
I have downloaded driver for Java named as Connector/J.
MySQL version is 5.0.
In this line
con = DriverManager.getConnection("jdbc:mysql://localhost/JSP_MYSQL?user=root&password=admin");

what is wrong where i have to give MySQL username and password and the name of the Database.

So please help me out.

It's Urgent.

Thanks..
<%! 
  Connection con = null;
  Statement state = null;
  ResultSet rs = null;
%>
<%
 try
 {
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  con = DriverManager.getConnection("jdbc:mysql://localhost/JSP_MYSQL?user=root&password=admin");
  state = con.createStatement();
  String s = "Select * from user.login";
  rs = state.executeQuery(s);
 }
 
 catch(SQLException e)
 {
  e.printStackTrace();
 }
 
%>
Last edited by Dhruv Shah : Feb 17th, 2007 at 3:20 am.
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 6:26 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC