这是我的代码: 用于将值插入数据库并显示数据库中的值
import java.sql.*;
class DbEx{
public static void main(String args[]) throws SQLException{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:jaga","","");
Statement s=c.createStatement();
s.execute("INSERT INTO stud VALUES(2,'Nirmal',23,'Btech','Male',720043)");
ResultSet rs=s.executeQuery("SELECT Id,Name FROM stud");
while(rs.next()){
System.out.println("ID"+rs.getInt(0)+"\nName"+rs.getString(1));
}
c.close();
}
catch(Exception e){
System.out.println(e);
}
}
}