如何用jfinal框架操作postgresql数据库,求具体代码操作。
下面是连接postgresql数据库代码
import java.sql.*;
public class DemoConfig {
public static void main(String[] args) {
try {
Class.forName("org.postgresql.Driver");
System.out.println("success loading Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("Fail loading Driver!");
e.printStackTrace();
}//加载驱动
String url="jdbc:postgresql://localhost/teacher";
String user="postgres";
String password="root";
try {
Connection nun=DriverManager.getConnection(url, user, password);
System.out.println("success connection service");
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("Connection URL or username or password errors!");
e.printStackTrace();
}
try{
Class.forName("org.postgresql.Driver").newInstance();
String connecturl ="jdbc:postgresql://localhost/teacher";
Connection conn = DriverManager.getConnection(url, user, password);
Statement st = conn.createStatement();
String sql = " SELECT 1;";
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getInt(1));
}
rs.close();
st.close();
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
是否有问题
下面是连接postgresql数据库代码
import java.sql.*;
public class DemoConfig {
public static void main(String[] args) {
try {
Class.forName("org.postgresql.Driver");
System.out.println("success loading Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("Fail loading Driver!");
e.printStackTrace();
}//加载驱动
String url="jdbc:postgresql://localhost/teacher";
String user="postgres";
String password="root";
try {
Connection nun=DriverManager.getConnection(url, user, password);
System.out.println("success connection service");
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("Connection URL or username or password errors!");
e.printStackTrace();
}
try{
Class.forName("org.postgresql.Driver").newInstance();
String connecturl ="jdbc:postgresql://localhost/teacher";
Connection conn = DriverManager.getConnection(url, user, password);
Statement st = conn.createStatement();
String sql = " SELECT 1;";
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getInt(1));
}
rs.close();
st.close();
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
是否有问题