Posts

Showing posts from March, 2008

How to Connect DataBase to Java Application -JDBC

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class db { public static void main(String[] args){ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc: mydb "); Statement stmt = conn.createStatement(); ResultSet results = stmt.executeQuery("SELECT * FROM student "); while(results.next()){ System.out.println(results.getString("SName")); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } }