try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn= DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\\DataBase1.mdb","","");
int id=Integer.parseInt(JOptionPane.showInputDialog("Enter ID"));
String name=JOptionPane.showInputDialog("Enter Name");
String Phone=JOptionPane.showInputDialog("Enter PHone");
String mobile=JOptionPane.showInputDialog("Enter Moblie");
//String sql="insert into friends values "id,'"+home
Statement ss=conn.createStatement();
ss.executeUpdate("insert into friends values("+id+",'"+name+"','"+Phone+"','"+mobile+"')");
Statement s=conn.createStatement();
ResultSet res=s.executeQuery("select*from friends order by id");
while(res.next()){
System.out.println(res.getString(1)+"\t"+res.getString(2)+"\t"+res.getString(3)+"\t"+res.getString(4));
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
这是我的代码,但是当我运行它时 此异常显示(“java.sql.SQLException: ??[Microsoft][ODBC Driver Manager] ?????? ??? ???”) 不知道是什么问题请帮忙???
最佳答案
使用PreparedStatement代替Statement怎么样?我认为您的代码不接受硬编码变量!并且,为了避免陷入更多麻烦,请记住关闭连接。
您还需要在星号周围留有空格“select * from Friends order by id”
关于java - 我需要连接我的 java 应用程序来访问 Windows 7 x64 中的数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10566770/