Statement stmt = Conn.createStatement();报错
importjava.sql.SQLException;importjava.sql.Statement;importjava.sql.Connection;import...
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class Conn {
public static void main(String[] args){
try{
//加载MySql的驱动类
Class.forName("com.mysql.jdbc.Driver") ;
}
catch(ClassNotFoundException e){
System.out.println("找不到驱动程序类 ,加载驱动失败!");
e.printStackTrace() ;
}
//jdbc:mysql:localhost:3306/test?useUnicode=true&characterEncoding=gbk ;
String url = "jdbc:mysql://localhost:3306/abc" ;
String username = "root" ;
String password = "123456" ;
try{
Connection Conn = DriverManager.getConnection(url , username , password ) ;
}
catch(SQLException se){
System.out.println("数据库连接失败!");
se.printStackTrace() ;
}
Statement stmt = Conn.createStatement();/*报错内容The method createStatement() is undefined for the type Conn */
ResultSet rs = stmt.executeQuery("SELECT * FROM abc") ;
}
} 展开
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class Conn {
public static void main(String[] args){
try{
//加载MySql的驱动类
Class.forName("com.mysql.jdbc.Driver") ;
}
catch(ClassNotFoundException e){
System.out.println("找不到驱动程序类 ,加载驱动失败!");
e.printStackTrace() ;
}
//jdbc:mysql:localhost:3306/test?useUnicode=true&characterEncoding=gbk ;
String url = "jdbc:mysql://localhost:3306/abc" ;
String username = "root" ;
String password = "123456" ;
try{
Connection Conn = DriverManager.getConnection(url , username , password ) ;
}
catch(SQLException se){
System.out.println("数据库连接失败!");
se.printStackTrace() ;
}
Statement stmt = Conn.createStatement();/*报错内容The method createStatement() is undefined for the type Conn */
ResultSet rs = stmt.executeQuery("SELECT * FROM abc") ;
}
} 展开
2个回答
2016-06-28
展开全部
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class Conn {
public static void main(String[] args){
try{
//加载MySql的驱动类
Class.forName("com.mysql.jdbc.Driver") ;
//jdbc:mysql:localhost:3306/test?useUnicode=true&characterEncoding=gbk ;
String url = "jdbc:mysql://localhost:3306/abc" ;
String username = "root" ;
String password = "123456"
Connection Conn = null;
try{
Conn = DriverManager.getConnection(url , username , password ) ; Statement stmt = Conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM abc") ;
} catch(SQLException se){
System.out.println("数据库连接失败!");
se.printStackTrace() ;
} finally{
if(Conn!=null ){
Conn.close();
}
}
}
catch(ClassNotFoundException e){
System.out.println("找不到驱动程序类 ,加载驱动失败!");
e.printStackTrace() ;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询