| User | Points |
|---|---|
| shamali | 4560 |
| Mujtaba | 1310 |
| Billy | 650 |
| maoo_o | 540 |
| Moin_iyan | 360 |
Lahore

Aslam-O-Alaikum!
I wana share one of my best code while in 5th Semester in PUCIT, it is very simple and straight forward and self explained to any who has basic know how about java jdbc concepts. It gives you the flexibility to put your access db file with your .class file on any system and don't need to configue DSN at all, just runyour java code.
Here is the Code snippet and also .java source file is attached with this post.
//---------------------------------------------------------------------------------------------------
import java.sql.*;
public class DirectDB{
public static void main(String args[]){
System.out.println("Starting");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "z:/sis.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection conn = DriverManager.getConnection( database ,"","");
// try and create a java.sql.Statement so we can run queries
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM table_name");
while(rs.next()){
//your business logic here.
}
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
}
}
//---------------------------------------------------------------------------------------------------
Note: Attachement is java code, please remove the extra .txt extension or paste the code directly to your java editor to work properly.
PUCIT ONLINE Team: Punjab University College of Information Technology
Best Regards,
Faial Basra
| Attachment | Size |
|---|---|
| DirectDB.java_.txt | 1.15 KB |
Nice Effort! I appericate to
Nice Effort!
I appericate to you for this effort and sharing.
I will be usefull for much more students of PUCIT.
Keep it up and try to share more informations regarding I.T. studies.
Thnx!
hi.. this is good one but if
hi..
this is good one but if u say that it is ur best code than this is not good.:D..
becoz this is a very basic thing and evryone knows about the JDBC drivers,,;)..
and u did it in ur 5th semester..amazing....good..