Skip to content

Instantly share code, notes, and snippets.

@mihirsam
Created September 27, 2018 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihirsam/b51023a3642bc78fe35b4d32ce134ad3 to your computer and use it in GitHub Desktop.
Save mihirsam/b51023a3642bc78fe35b4d32ce134ad3 to your computer and use it in GitHub Desktop.
import java.sql.*;
public class UserLogin2
{
public static void main(String args[])
{
try
{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//String url = "jdbc:odbc:Driver={MicrosoftAccessDriver(*.mdb,*.accdb)};DBQ=+"C:\Users\RONITA DEBNATH\Documents\Student.accdb";
Connection conn;
conn = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\Chandni\\Documents\\Student.accdb");
System.out.println("Connection Successfull");
Statement stmt;
stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from Stu");
if(rs!=null)
{
while(rs.next())
{
System.out.println("ID:"+rs.getString(1)+"Name:"+rs.getString(2));
}
}
stmt.close();
conn.close();
}
catch(Exception e)
{
System.err.println("got an exception");
System.err.println(e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment