[英]Error in postgres driver in jdbc
我嘗試使用JDBC為postgres創建驅動程序,但我在驅動程序管理器中收到錯誤。 我該如何修復此代碼?
import java.sql.*;
public class jdbc {
public static void main(String[] args) {
try {
Class.forName("org.postgresql.Driver");
Connection con=DriverManager.getConnection("jdbc:postgresql://localhost:5432/dvdrental2","postgres","vibhug");
System.out.println("Opened database successfully");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from actor ");
while(rs.next())
{
int actor_id = rs.getInt("actor_id");
String first_name = rs.getString("first_name");
int last_name = rs.getInt("last_name");
System.out.println( "ID = " + actor_id );
System.out.println( "fNAME = " + first_name );
System.out.println( "AGE = " + last_name );
System.out.println();
}
con.close();
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("operation done successfully!!!");
}
}
好像你正試圖檢索last_name
,這很可能是一個字符串作為int
。 修復它,它應該沒問題:
String last_name = rs.getString("last_name");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.