mysql与java连接实现增删改 数据库数据。我写了连接的代码如下,请帮我补充下被,或者发整个代码也行。 20
packagecom;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.Resu...
package com;
import java.sql.Connection;import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBTest {
/** * @param args
*/
public static void main(String[] args) throws ClassNotFoundException,SQLException {
// TODO Auto-generated method stub
Class.forName("com.mysql.jdbc.Driver");
String ur1 ="jdbc:mysql://localhost:3306/scutcs";
String user = "root";
String password = "123456";
Connection con = DriverManager.getConnection(ur1,user,password);
if(!con.isClosed()){
System.out.println("1");
}else{
System.out.println("2");
}
public Connection getConnection() { Connection con = null;
try {
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
}
我的邮箱526779789
@qq.com 展开
import java.sql.Connection;import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBTest {
/** * @param args
*/
public static void main(String[] args) throws ClassNotFoundException,SQLException {
// TODO Auto-generated method stub
Class.forName("com.mysql.jdbc.Driver");
String ur1 ="jdbc:mysql://localhost:3306/scutcs";
String user = "root";
String password = "123456";
Connection con = DriverManager.getConnection(ur1,user,password);
if(!con.isClosed()){
System.out.println("1");
}else{
System.out.println("2");
}
public Connection getConnection() { Connection con = null;
try {
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
}
我的邮箱526779789
@qq.com 展开
1个回答
展开全部
public static Connection GetJDBCConn() {
Connection conn = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(ur1,user,password);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
Connection conn = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(ur1,user,password);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询