|
import java.sql.*;
public class Dbtest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(" this is a test " );
try
{
Class.forName( "org.postgresql.Driver" ).newInstance();
String url = "jdbc:postgresql://localhost:5432/hktrade" ;
System.out.println("aaa");
Connection con = java.sql.DriverManager.getConnection(url, "postgres" , "Fourk8006" );
if (con!=null)
{System.out.println("connect");}
else
{System.out.print("can't connect");};
Statement st = con.createStatement();
String sql = "select ucode ,password from poweruser " ;
ResultSet rs = st.executeQuery(sql);
System.out.print("maxrows:");
while (rs.next())
{
System.out.print(rs.getString(1));
System.out.println(rs.getString(2));
}
rs.close();
st.close();
con.close();
}
catch (Exception ee)
{
System.out.println("error");
System.out.print(ee.getMessage());
}
}
} |
|
|