Results 1 to 3 of 3
- 04-20-2012, 02:59 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
Java with MS Access Database User login
Friends need help...
I'm trying to Connect with MS Access database.. and the connection succesfully established .. but when i'm trying to check whether username and password is matching or not with databse login table ..its not working..
might be there is a Problem with try block inside check method... check image also..
Database Name=loginuser1
Table Name=login
I have also configured the ODBC data source ....
Below is the code...
import java.sql.*;
public class check{
Connection con;
Statement st;
ResultSet rs;
public check(){
connect();
}
public void connect(){
try{
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
String db="jdbc:odbc:loginuser1";
con=DriverManager.getConnection(db);
st=con.createStatement();
System.out.println("Connection established");
}
catch(Exception ex){
System.out.println("Connection problem"+ex);
}
}
public static void main(String[] args){
String userName="Deepak";
int password=123;
check ck=new check();
ck.check(userName,password);
}
public void check(String userName,int password){
try{
String sql="select user,pass from login where user='"+userName+"'pass='"+password+"'";
rs=st.executeQuery(sql);
System.out.println(rs);
int count=0;
while(rs.next()){
count=count+1;
}
if(count==1){
System.out.println("SQL done");
}else{
System.out.println("again error");
}
}catch(Exception ex){System.out.println("Problem with query...");}-------->(showing this user-defined error)
}
}
problem with try block...
- 04-20-2012, 03:01 PM #2
Member
- Join Date
- Apr 2012
- Posts
- 27
- Rep Power
- 0
- 04-20-2012, 03:24 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,447
- Rep Power
- 16
Re: Java with MS Access Database User login
1. Please use [code] tags [/code] when posting code so it retains formatting and is readable.
2. When catching exceptions it's advisable to do <exception>.printStackTrace() to get as much information about the exception as possible.
3. Finally, I'd recommend using a PreparedStatement and binding (eg setString()) the variables in. Concatenating your parameters into your SQL like that invariably leads to bugs.Please do not ask for code as refusal often offends.
Similar Threads
-
how to login to website to get access using java?
By theChameleon in forum Advanced JavaReplies: 0Last Post: 10-29-2010, 06:20 PM -
Login page which connects to database that verifies user
By Neutrino in forum JDBCReplies: 1Last Post: 03-15-2010, 01:39 AM -
Single login for a user at a time
By mitali l joshi in forum Java ServletReplies: 4Last Post: 01-22-2010, 10:23 AM -
cannot open database requested in login. Login fails
By banduskank in forum JDBCReplies: 0Last Post: 06-25-2008, 12:41 PM -
Login user name - for all platforms.
By Eranga in forum Advanced JavaReplies: 0Last Post: 03-17-2008, 05:45 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks