Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.04 KB | None | 0 0
  1. I have problem trying to run this. Always I get No driver, I dont know anything else, I am using windows and for compiling I get this
  2.  
  3. D:\Asterisk-Java\test\ivr>javac -cp .\ivrlib\lib\postgresql-8.3-603.jdbc4.jar DBtest2.java
  4. And run like this
  5.  
  6. >java DBtest2
  7. No driver
  8.  
  9. import java.sql.*;
  10.  
  11.     class DBtest2{
  12.     public static void main(String[] args)
  13.     {
  14.     String driver ="org.postgresql.Driver";
  15.     String connectString = "jdbc:postgresql://10.10.10.10:5432/db";
  16.     String user = "xxxx";
  17.     String password = "qqqqq";
  18.  
  19.     try{
  20.     Class.forName(driver);
  21.     Connection con = DriverManager.getConnection(connectString, user , password);
  22.     Statement stmt = con.createStatement();
  23.  
  24.     ResultSet rs = stmt.executeQuery("select f_celular from t_clientes");
  25.  
  26.     while (rs.next()){
  27.     System.out.println("celular::" + rs.getString("f_celular"));
  28.     }
  29.  
  30.     stmt.close();
  31.     con.close();
  32.  
  33.     }
  34.  
  35.     catch ( Exception e ){
  36.     System.out.println("No driver");
  37.     System.out.println(e.getMessage());
  38.     }
  39.     }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement