用Java进行数据库连接,Connection con = new Connection(urlName);时,出现编译错误
2个回答
展开全部
是这个样子的,
public static Connection getDconn() throws Exception{
Connection conn=null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/mydata?user=root&password=root");
}catch(Exception ex){
throw new Exception("数据库连接失败");
}
return conn;
}
当然不能那样了.
public static Connection getDconn() throws Exception{
Connection conn=null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/mydata?user=root&password=root");
}catch(Exception ex){
throw new Exception("数据库连接失败");
}
return conn;
}
当然不能那样了.
展开全部
jdbc操作如下:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection(urlName);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from 表");
while(rs.next()){
System.out.println(rs.getString("字段"));
}
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection(urlName);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from 表");
while(rs.next()){
System.out.println(rs.getString("字段"));
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询