java中jdbc怎么链接sqlserver数据库,请高手帮帮 1.java中jdbc怎么链接sqlserver数据库??2.有几种连接sqlserver数据库方法3.有没有链接sqlserver的thin方法4.能不能写一下代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;/** * 驱动程序加载以及建立数据联接工具类 * @author xiaohai */public class DataConnection { /** * 驱动程序加载以及建立数据联接 * @return Connection 对象 * @throws ClassNotFoundException * @throws SQLException */ public static Connection getConnection() throws ClassNotFoundException, SQLException{ // 加载驱动程序 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); // 连接数据库字符串 String url = "jdbc:microsoft:sqlserver://localhost:1433(端口);DatabaseName=数据库名称"; // 返回数据库连接 return DriverManager.getConnection(url, "数据库用户名", "数据库密码"); } } public class DataBase { public Connection conn; public Statement stmt; public ResultSet rs=null; public String sqlstr=""; public DataBase(){ this.connect(); } public boolean connect(){ try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=stockpile_ms"; String user="sa"; String password="123456"; Connection conn= DriverManager.getConnection(url,user,password); stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); }catch(Exception e){ System.out.println("Connect Sql server error:"+e.getMessage()); return false; } return true; } public static void main(String[] args){ try{ DataBase db=new DataBase(); db.connect(); }catch(Exception e){ e.printStackTrace(); } }} public boolean query() throws Exception{ try{ DataBase db=new DataBase(); String cur_Invoiceid = this.getInvoice_id(); String cur_Supplier_company = this.getSupplier_company(); String cur_purchase_person = this.getPurchase_person(); db.connect(); String sql= "Select * From Storage_inventories where Storage_inventories.invoice_isregistrated=1 and Storage_inventories.credentials_num like '%"+cur_Invoiceid+"%'" +" and Storage_inventories.supplier_company like '%"+cur_Supplier_company+"%' and Storage_inventories.purchase_person like'%"+cur_purchase_person+"%'"; System.out.println(sql); rs=db.stmt.executeQuery(sql); }catch(Exception e){ System.out.println("Connect Sql server error:"+e.getMessage()); return false; } int cur_pagecount = 0; int cur_pagesize = 100; int cur_recordcount = 0; list =new Vector();//申请空间,以向量形式存储每一条记录。 while(rs.next()){ Storage_Inventories storage_inventories = new Storage_Inventories(); storage_inventories.setPurchasePlan_num(rs.getString("purchasePlan_num")); storage_inventories.setType_num1(rs.getString("type_num1")); storage_inventories.setType_num2(rs.getString("type_num2")); storage_inventories.setType_num3(rs.getString("type_num3")); storage_inventories.setMaterial_num(rs.getString("material_num")); storage_inventories.setMaterial_name(rs.getString("material_name")); storage_inventories.setSize(rs.getString("size")); storage_inventories.setUnit(rs.getString("unit")); storage_inventories.setQuantity(rs.getFloat("quantity")); storage_inventories.setApproval_quantity(rs.getFloat("approval_quantity")); storage_inventories.setUnitprice(rs.getFloat("unitprice")); storage_inventories.setReal_unitprice(rs.getDouble("real_unitprice")); storage_inventories.setSupplier_company(rs.getString("supplier_company")); storage_inventories.setDate(rs.getString("date")); storage_inventories.setPurchase_person(rs.getString("purchase_person")); storage_inventories.setPlan_person_approval(rs.getBoolean("plan_person_approval")); storage_inventories.setBoss_approval(rs.getBoolean("boss_approval")); storage_inventories.setInvoice_isregistrated(rs.getBoolean("invoice_isregistrated")); storage_inventories.setIs_checkout(rs.getBoolean("is_checkout")); storage_inventories.setCredentials_num(rs.getString("credentials_num")); cur_recordcount++; if(cur_recordcount==cur_pagesize){ cur_pagecount++; cur_recordcount=0; } list.addElement(storage_inventories); } if(cur_recordcount!=0)cur_pagecount++; cur_recordcount+=(cur_pagecount-1)*cur_pagesize; this.setPageCount(cur_pagecount); this.setPageSize(cur_pagesize); this.setRecordCount(cur_recordcount); this.setPageId(1); return true; } 有个输入法不支持64位,谁能解决 项目打包成jar之后无法实现对文件的写操作(应该是路径的问题,不知如何去改) 行情 读取指定IP的mib库,实现set,get,getnext等操作 这么写对吗?ShapeCircle.java这文件怎么编译不过去啊?? 这是这么回事? byte怎么进行位运算阿 排序算法求助,急! 怎样才能让一段代码每隔一段时间执行一次?急求!在线等!!! 一个关于数组的问题,谢谢 在java中怎样获取局域网ip地址 我哭啊!难为了好几天的问题! 不明白什么原因!高手指点
import java.sql.DriverManager;
import java.sql.SQLException;/**
* 驱动程序加载以及建立数据联接工具类
* @author xiaohai
*/
public class DataConnection { /**
* 驱动程序加载以及建立数据联接
* @return Connection 对象
* @throws ClassNotFoundException
* @throws SQLException
*/
public static Connection getConnection() throws ClassNotFoundException, SQLException{
// 加载驱动程序
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
// 连接数据库字符串
String url = "jdbc:microsoft:sqlserver://localhost:1433(端口);DatabaseName=数据库名称";
// 返回数据库连接
return DriverManager.getConnection(url, "数据库用户名", "数据库密码");
}
}
public Connection conn;
public Statement stmt;
public ResultSet rs=null;
public String sqlstr="";
public DataBase(){
this.connect();
}
public boolean connect(){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=stockpile_ms";
String user="sa";
String password="123456";
Connection conn= DriverManager.getConnection(url,user,password);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}catch(Exception e){
System.out.println("Connect Sql server error:"+e.getMessage());
return false;
}
return true;
}
public static void main(String[] args){
try{
DataBase db=new DataBase();
db.connect();
}catch(Exception e){
e.printStackTrace();
}
}
}
public boolean query() throws Exception{
try{
DataBase db=new DataBase();
String cur_Invoiceid = this.getInvoice_id();
String cur_Supplier_company = this.getSupplier_company();
String cur_purchase_person = this.getPurchase_person();
db.connect();
String sql= "Select * From Storage_inventories where Storage_inventories.invoice_isregistrated=1 and Storage_inventories.credentials_num like '%"+cur_Invoiceid+"%'"
+" and Storage_inventories.supplier_company like '%"+cur_Supplier_company+"%' and Storage_inventories.purchase_person like'%"+cur_purchase_person+"%'";
System.out.println(sql);
rs=db.stmt.executeQuery(sql);
}catch(Exception e){
System.out.println("Connect Sql server error:"+e.getMessage());
return false;
}
int cur_pagecount = 0;
int cur_pagesize = 100;
int cur_recordcount = 0;
list =new Vector();//申请空间,以向量形式存储每一条记录。
while(rs.next()){
Storage_Inventories storage_inventories = new Storage_Inventories();
storage_inventories.setPurchasePlan_num(rs.getString("purchasePlan_num"));
storage_inventories.setType_num1(rs.getString("type_num1"));
storage_inventories.setType_num2(rs.getString("type_num2"));
storage_inventories.setType_num3(rs.getString("type_num3"));
storage_inventories.setMaterial_num(rs.getString("material_num"));
storage_inventories.setMaterial_name(rs.getString("material_name"));
storage_inventories.setSize(rs.getString("size"));
storage_inventories.setUnit(rs.getString("unit"));
storage_inventories.setQuantity(rs.getFloat("quantity"));
storage_inventories.setApproval_quantity(rs.getFloat("approval_quantity"));
storage_inventories.setUnitprice(rs.getFloat("unitprice"));
storage_inventories.setReal_unitprice(rs.getDouble("real_unitprice"));
storage_inventories.setSupplier_company(rs.getString("supplier_company"));
storage_inventories.setDate(rs.getString("date"));
storage_inventories.setPurchase_person(rs.getString("purchase_person"));
storage_inventories.setPlan_person_approval(rs.getBoolean("plan_person_approval"));
storage_inventories.setBoss_approval(rs.getBoolean("boss_approval"));
storage_inventories.setInvoice_isregistrated(rs.getBoolean("invoice_isregistrated"));
storage_inventories.setIs_checkout(rs.getBoolean("is_checkout"));
storage_inventories.setCredentials_num(rs.getString("credentials_num"));
cur_recordcount++;
if(cur_recordcount==cur_pagesize){
cur_pagecount++;
cur_recordcount=0;
}
list.addElement(storage_inventories);
}
if(cur_recordcount!=0)cur_pagecount++;
cur_recordcount+=(cur_pagecount-1)*cur_pagesize;
this.setPageCount(cur_pagecount);
this.setPageSize(cur_pagesize);
this.setRecordCount(cur_recordcount);
this.setPageId(1);
return true;
}