求一个JSP的小程序,有的给我发过来呗,奖励100分
2个回答
展开全部
package com.etong.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcCoon {
public static Connection con = null;// Connection("127.0.0.1", "1433", "sa", "sa","test");
public static Connection Connection(String ip,String port,String username,String pwd,String database) {
String ClssForName="net.sourceforge.jtds.jdbc.Driver";
String url="jdbc:jtds:sqlserver://"+ip+":"+port+";DatabaseName="+database;
try{
Class.forName(ClssForName); //加载驱动程序
con=DriverManager.getConnection(url,username,pwd); //通过驱动管理器(DriverManager)建立连接
System.out.println("数据库连接成功!");
} catch (ClassNotFoundException e) {
//e.getMessage();
//undo
con = null;
return null;
}catch(SQLException cone){
cone.getMessage();
// undo
con = null;
return null;
}
return con;
}
public static Connection getConnection() {
JdbcCoon jc = new JdbcCoon();// 创建JdbcCoon对象
Connection cn = jc.Connection("127.0.0.1", "1433", "sa", "sa1234", "lyb");// 调用对象方法
return cn;// 返回Connection 对象
}
public static void main(String[] args) {
// JdbcCoon jc = new JdbcCoon();
// Connection cn = jc.Connection("127.0.0.1", "1433", "sa", "sa", "lyb");
// System.out.println(cn);
if (1 == 1) {
System.out.print("123");
System.out.print("456");
}
}
}
链接SQLserver代码
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcCoon {
public static Connection con = null;// Connection("127.0.0.1", "1433", "sa", "sa","test");
public static Connection Connection(String ip,String port,String username,String pwd,String database) {
String ClssForName="net.sourceforge.jtds.jdbc.Driver";
String url="jdbc:jtds:sqlserver://"+ip+":"+port+";DatabaseName="+database;
try{
Class.forName(ClssForName); //加载驱动程序
con=DriverManager.getConnection(url,username,pwd); //通过驱动管理器(DriverManager)建立连接
System.out.println("数据库连接成功!");
} catch (ClassNotFoundException e) {
//e.getMessage();
//undo
con = null;
return null;
}catch(SQLException cone){
cone.getMessage();
// undo
con = null;
return null;
}
return con;
}
public static Connection getConnection() {
JdbcCoon jc = new JdbcCoon();// 创建JdbcCoon对象
Connection cn = jc.Connection("127.0.0.1", "1433", "sa", "sa1234", "lyb");// 调用对象方法
return cn;// 返回Connection 对象
}
public static void main(String[] args) {
// JdbcCoon jc = new JdbcCoon();
// Connection cn = jc.Connection("127.0.0.1", "1433", "sa", "sa", "lyb");
// System.out.println(cn);
if (1 == 1) {
System.out.print("123");
System.out.print("456");
}
}
}
链接SQLserver代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询