我已經正確創建dsn,並有清晰和簡單的代碼,但我最終得到這個錯誤。表結構是一樣的程序當我想插入數據到MySQL使用JdbcOdbc橋驅動程序,我沒有得到數據庫選擇的錯誤,
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Insert {
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbc");
Connection con=DriverManager.getConnection("jdbc:odbc:mysqldsn","root","filimon");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into emp values(3,'cat')");
if (i>=1) {
System.out.println("inserted successfully");
} else {
System.out.println("failed");
}
st.close();
con.close();
} catch (Exception e) {
System.err.println(e);
}
}
}
我得到java.sql.SQLException中:[MySQL的] [ODBC 5.3(A)驅動程序]的[mysqld-5.7.13日誌]沒有數據庫中選擇
非常感謝,我修好了 –
歡迎,任何時間。 –