创建连接时出错或错误的代码类型&;在java中使用mysql执行SQL查询语句
我在Eclipse中使用MySQL 5.7和Java,下面代码中的连接语句在我尝试连接时导致错误:创建连接时出错或错误的代码类型&;在java中使用mysql执行SQL查询语句,java,mysql,eclipse,macos,Java,Mysql,Eclipse,Macos,我在Eclipse中使用MySQL 5.7和Java,下面代码中的连接语句在我尝试连接时导致错误: try { //1. Get a connection to database jdbc:mysql://localhost:3306/databaseName?autoReconnect=true;useSSL=false; // 2. Create a statement Statement myStmt=
try
{
//1. Get a connection to database
jdbc:mysql://localhost:3306/databaseName?autoReconnect=true;useSSL=false;
// 2. Create a statement
Statement myStmt=myConn.createStatement();
// 3. Execute SQL query
ResultSet myRs=myStmt.executeQuery("select * from employee");
//4. Process the result set
while(myRs.next())
{
System.out.println(myRs.getString("last_name")+","+myRs.getString("first_name"));
}
}
catch(Exception exc){
exc.printStackTrace();
}
第一件事
代码将仅用于验证错误。因此,必须粘贴程序触发的错误
由于我们没有足够的信息来解决这个问题,我将只介绍基本的故障排除
基本故障排除:
Class.forName(“com.mysql.jdbc.Driver”);//在做任何事情之前,像这样加载驱动程序
statement s=con.createStatement();//创建语句
。这将用于执行sql命令s.execute(“select*from employee”);//执行Query
注意s这里是在数字5上创建的变量希望它能帮助你和其他需要它的人。myConn来自哪里?另外,您的代码中有一个随机字符串,我假设这是您试图创建连接的方式,但导致错误出现在代码的其他位置。欢迎使用Stackoverflow。复制和粘贴问题中的错误总是好的,这样人们就可以帮助你解决问题。