您好,我想将java程序里连接mysql的语句换成连接SqlServer的语句,代码怎么改?
publicclassbaseDao{privatestaticConnectionconn;//定义连接对象privatestaticStatementstmt;//创...
public class baseDao {
private static Connection conn; //定义连接对象
private static Statement stmt;//创建事物
private static ResultSet rs; //创建结果集对象
public baseDao()
{
String mysqlDriver="com.mysql.jdbc.Driver";
String mysqlURL="jdbc:mysql://localhost:3306/zxks";
String mysqlUser="root";
String mysqlPassword="root";
try{
Class.forName(mysqlDriver); //加载驱动
//System.out.println("加载驱动成功!!!");
}
catch(Exception e){
//System.out.println("加载驱动失败!!!");
e.printStackTrace();
}
try{
conn=DriverManager.getConnection(mysqlURL,mysqlUser,mysqlPassword);
stmt=conn.createStatement();
if(!conn.isClosed())
System.out.println("数据库连接成功!!");
}catch (SQLException ex){
System.out.println("数据库连接失败!!");
ex.printStackTrace();
}
} 展开
private static Connection conn; //定义连接对象
private static Statement stmt;//创建事物
private static ResultSet rs; //创建结果集对象
public baseDao()
{
String mysqlDriver="com.mysql.jdbc.Driver";
String mysqlURL="jdbc:mysql://localhost:3306/zxks";
String mysqlUser="root";
String mysqlPassword="root";
try{
Class.forName(mysqlDriver); //加载驱动
//System.out.println("加载驱动成功!!!");
}
catch(Exception e){
//System.out.println("加载驱动失败!!!");
e.printStackTrace();
}
try{
conn=DriverManager.getConnection(mysqlURL,mysqlUser,mysqlPassword);
stmt=conn.createStatement();
if(!conn.isClosed())
System.out.println("数据库连接成功!!");
}catch (SQLException ex){
System.out.println("数据库连接失败!!");
ex.printStackTrace();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询