I am trying to connect to a database with a username and a password through
Jsp but I am getting error:
I have a Login Page that calls the process page to ]connect to the database
process page:
<html>
<%@ page import = "java.sql.*, dbConnect.ConnectClass" page ="java"%>
<jsp:useBean id = "myCBean" class="dbConnect.ConnecClass" scope="session"/>
<%
String path = request.getContextPath();
String basePath = "http://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<base href="<%=basePath%>">
Accessing database please wait........ <br>
<% myCBean.DbInit(); %>
Database connection is initialized successfully! <hr>
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
</body>
<% myCBean.DbClose(); %>
Database connection is closed!
</html>
my class to connect and check password
package dbConnect;
import java.sql.*;
public class ConnectClass {
private String username = "";
private String password = "";
public ConnectClass() {
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void DbInit() throws SQLException{
public boolean authenticate(String username2,String password2) {
String query = "select * from WIZUSUARIOS;";
String DbUserName = "";
String DbPassword = "";
String finalUser = "";
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://servername:1433");
Statement stat = con.createStatement();
ResultSet rst = stat.executeQuery(query);
while(rst.next()){
DbUserName = rst.getString("UserName");
DbPassword = rst.getString("password");
if (username2.equals(DbUserName) && password2.equals(DbPassword)) {
break;
}
}
return true;
}//try
catch(Exception e){
e.printStackTrace();
return false;
}
}//authenticate
}//dbInit
}
I am getting an error like error on token "(" ";" in the public boolean authenticate(String username2,String password2)
and in the process page.
Can anyone help with this because Iam running out of time I want to connect to database with JSP with a username and password and be able to change the username and password.
Thank you very much