Database connection

Reply

Join Date: May 2008
Posts: 1
Reputation: Ragini.gudiya is an unknown quantity at this point 
Solved Threads: 0
Ragini.gudiya Ragini.gudiya is offline Offline
Newbie Poster

Re: How to Connect MySQL from JSP Page

 
0
  #1
Jun 3rd, 2008
Hi
i m new in mysql plz any one help me how can i solve a problem.

i m using this code for connection file


  1. package connect;
  2.  
  3. import java.sql.*;
  4.  
  5. public class Connect
  6. {
  7. private static Connection con=null;
  8.  
  9. public static Connection getConnection()
  10. {
  11. try
  12. {
  13. Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  14. con =DriverManager.getConnection("jdbc:mysql://localhost:3306/rsdatabase","root","root");
  15.  
  16. System.out.println("Connection Established");
  17. return con;
  18. }
  19. catch(Exception e)
  20. {
  21. System.out.println("Error Loading Driver" +e);
  22. }
  23. return con;
  24. }
  25. }

and also made this page


  1. package services;
  2. import java.sql.*;
  3. import java.io.*;
  4. import java.util.*;
  5. import connect.Connect;
  6. public class login1
  7. {
  8. Vector v=null,v1=null,v2=null,v3=null,v4=null,v5=null,v6=null,v7=null,v8=null;
  9. Connection con=null;
  10. Statement stmt=null,stmt1=null,stmt2=null;
  11. ResultSet rs=null,rs1=null,rs2=null;
  12. PreparedStatement ps=null,ps1=null,ps2=null;
  13. public login1() {
  14. try {
  15. con=Connect.getConnection();
  16. }
  17. catch(Exception e)
  18. {
  19. System.out.println("Exception:"+e);
  20. }
  21. }
  22. public boolean logincheck(String username,String password) {
  23. try{
  24. String aa="Select * from user_pass where UserName=(?) and password=(?)";
  25. ps=con.prepareStatement(aa);
  26. ps.setString(1,username);
  27. ps.setString(2,password);
  28. rs=ps.executeQuery();
  29. if(rs.next()){
  30. return true;
  31. }
  32. }
  33. catch(Exception s) {
  34. System.out.println("Error" +s);
  35. }
  36. return false;
  37. }
  38. public String getType(String username,String password) {
  39. try{
  40. String aa="Select * from user_pass where UserName=(?) and password=(?)";
  41. ps=con.prepareStatement(aa);
  42. ps.setString(1,username);
  43. ps.setString(2,password);
  44. rs=ps.executeQuery();
  45. if(rs.next()){
  46. return rs.getString("AccessType");
  47. }
  48. }
  49. catch(Exception s) {
  50. System.out.println("Error" +s);
  51. }
  52. return "-";
  53. }
  54. public static void main(String args[]) {
  55. login1 ll=new login1();
  56. boolean b=ll.logincheck("admin","admin");
  57. System.out.println(b);
  58. }
  59. }
i m using tomcat 4.0 and
if i m insert a id and pwd admin,admin then give the error

Database Connection does not exist


plz help me how can i solve this problem
Last edited by peter_budo; Jun 3rd, 2008 at 11:02 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC