Monday, 17 December 2012

Selenium database connection

import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;


public class dbprog {
    public static void main(String[] args) throws Exception {
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     Connection conn = DriverManager.getConnection("jdbc:odbc:ds1","", "");
     Statement st=conn.createStatement();
     ResultSet rs1 = st.executeQuery("select title,price,t.pub_id,pub_name from titles t,publishers p where t.pub_id=p.pub_id");
     while (rs1.next())
     {
         System.out.println(rs1.getString(1)+" "+rs1.getInt(2) + " " + rs1.getString(3)+" "+rs1.getString(4));
        
     }
     conn.close();
    }
}

No comments:

Post a Comment