can some one help me

Reply

Join Date: Oct 2009
Posts: 1
Reputation: izzet is an unknown quantity at this point 
Solved Threads: 0
izzet izzet is offline Offline
Newbie Poster

can some one help me

 
0
  #1
Oct 14th, 2009
I want to create a login jsp form that connect with servlet and mysql for database. And I'm using netbeans and glassfishV2. Please help me to solve this problem.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,279
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 494
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer
 
-1
  #2
Oct 14th, 2009
Netbeans.org - Creating a Simple Web Application Using a MySQL Database

PS: Do not limit your self to selected tools, try others or try also tutorials that are not directly fitting your tool set and modify as need it.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: pardon_garden is an unknown quantity at this point 
Solved Threads: 0
pardon_garden pardon_garden is offline Offline
Newbie Poster
 
0
  #3
Oct 15th, 2009
Use a JDBC for connection and call this when connecting to the database. USe a servlet to take the details from the JSP then validate by querying the database by using some check class i.e. Boolean checkUser(username, password).
Return true if they exist and false if they do not. Here is an example JDBC -
  1. package DatabaseConnection;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DatabaseMetaData;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10.  
  11. public class JDBCConnector {
  12. String dbDriver = "your_db_connection";
  13. String userId="db_userId"; // individual user id
  14. String password="db_password"; // individual password
  15. String dbURL =
  16. "db_location"+userId+"&password="+password;
  17.  
  18. private Connection dbCon;
  19. private DatabaseMetaData dbMetaData;
  20. private Statement stmt;
  21.  
  22. public JDBCConnector() {
  23. super();
  24. }
  25.  
  26. public boolean connect()
  27. throws
  28. ClassNotFoundException,
  29. SQLException,
  30. InstantiationException,
  31. IllegalAccessException {
  32.  
  33. Class.forName(this.getDbDriver()).newInstance();
  34. dbCon = DriverManager.getConnection(this.getDbURL());
  35. return true;
  36. }
  37.  
  38. public void close() throws SQLException {
  39. dbCon.close();
  40. }
  41.  
  42. public void commit() throws SQLException {
  43. dbCon.commit();
  44. }
  45.  
  46. public void setAutoCommit(boolean autocommit) throws SQLException {
  47. dbCon.setAutoCommit(autocommit);
  48. }
  49.  
  50. public void rollback() throws SQLException {
  51. dbCon.rollback();
  52. }
  53.  
  54. public PreparedStatement prepareStatement(String sql) throws SQLException {
  55. PreparedStatement s = dbCon.prepareStatement(sql);
  56. return s;
  57. }
  58.  
  59. public Statement createStatement() throws SQLException {
  60. Statement s = dbCon.createStatement();
  61. return s;
  62. }
  63.  
  64. public int executeUpdate(String s) throws SQLException {
  65. int count = stmt.executeUpdate(s);
  66. return count;
  67. }
  68.  
  69. public ResultSet execSQL(StringBuffer sqlBuf) throws SQLException {
  70. Statement s = dbCon.createStatement();
  71. String sql = sqlBuf.toString();
  72. ResultSet rs = s.executeQuery(sql);
  73. return (rs == null) ? null : rs;
  74. }
  75.  
  76. public String getDbDriver() {
  77. return this.dbDriver;
  78. }
  79.  
  80. public void setDbDriver(String newValue) {
  81. this.dbDriver = newValue;
  82. }
  83.  
  84. public String getDbURL() {
  85. return this.dbURL;
  86. }
  87.  
  88. public void setDbURL(String newValue) {
  89. this.dbURL = newValue;
  90. }
  91.  
  92. public ResultSet doQuery(StringBuffer qry) {
  93. Connection con = null;
  94. Statement stmt = null;
  95.  
  96. // set variables to take in resultset values
  97. String returnedUserName = null;
  98. String returnedPassword = null;
  99. ResultSet rs = null;
  100.  
  101. try {
  102. connect();
  103. rs = execSQL(qry);
  104.  
  105. } catch (ClassNotFoundException e) {
  106. System.out.println("ClassNotFound: " + e.getMessage());
  107. } catch (SQLException e) {
  108. System.out.println("SQLException: " + e.getMessage());
  109. } catch (InstantiationException e) {
  110. System.out.println("InstantiationException: " + e.getMessage());
  111. } catch (IllegalAccessException e) {
  112. System.out.println("IllegalAccessException: " + e.getMessage());
  113. }
  114. return rs;
  115. }
  116.  
  117. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #4
Oct 15th, 2009
To pardon_garden

  1. ResultSet rs = s.executeQuery(sql);
  2. return (rs == null) ? null : rs;

First of all, this:
ResultSet rs = s.executeQuery(sql); never returns null

And also this is very "not inteligent":
return (rs == null) ? null : rs; If it is null return null, if it is not null return itself???????
It is exactly the same as
return rs;
Also you do this:
Statement s = dbCon.createStatement(); but I don't see where this instance can be closed?
The same goes for the "doQuery" method where you define 2 unnecessary variables even though you have global as well.

Peter_budo has created this amazing tutorial:
JSP database connectivity according to Model View Controller (MVC) Model 2
Why did you post this amateur code?
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: pardon_garden is an unknown quantity at this point 
Solved Threads: 0
pardon_garden pardon_garden is offline Offline
Newbie Poster
 
0
  #5
Oct 15th, 2009
Because my amateur code still works.

By using the command db.close() the following method is invoked
  1. public void close() throws SQLException {
  2. dbCon.close();
  3. }

and the connection is closed.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #6
Oct 15th, 2009
Originally Posted by pardon_garden View Post
Because my amateur code still works.

By using the command db.close() the following method is invoked
  1. public void close() throws SQLException {
  2. dbCon.close();
  3. }

and the connection is closed.
And the Statement? Where do you close it?
Also you have a Statement declared globally and inside the method I described you open one locally, and you don't have methods to close neither of them.

Also you do this:
  1. public int executeUpdate(String s) throws SQLException {
  2. int count = stmt.executeUpdate(s);
  3. return count;
  4. }
Where do you create the "stmt"? I am sorry but I didn't see it. I could be wrong.
Last edited by javaAddict; Oct 15th, 2009 at 9:33 am.
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #7
Oct 15th, 2009
Originally Posted by izzet View Post
I want to create a login jsp form that connect with servlet and mysql for database. And I'm using netbeans and glassfishV2. Please help me to solve this problem.
I am sorry for not contributing much to your question apart for my comments to pardon_garden code.
The link that I provided should be able to help you start. Also try Peter_budo's link
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 438 | Replies: 6
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC