java mssql jtds
本文地址:http://tongxinmao.com/Article/Detail/id/130
package com.shubeitong.park; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; //jtds下载地址:http://sourceforge.net/projects/jtds/files/latest/download public class Main { String dbURL = "jdbc:jtds:sqlserver://127.0.0.1:1433;;DatabaseName=rr"; String user = "sa"; String password = "888"; Connection conn; public Main(){ this.connect(); this.test(); } public void connect(){ try{ try{ Class.forName("net.sourceforge.jtds.jdbc.Driver"); }catch(Exception e){ e.printStackTrace(); } //DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver()); conn = DriverManager.getConnection(dbURL,user,password); DatabaseMetaData metaData = conn.getMetaData(); System.out.println("DatabaseProductVersion:"+metaData.getDatabaseProductVersion()); }catch(Exception e){ e.printStackTrace(); } } public void test(){ // Select CarNo,ID,CardID,PCardType,PInTime from Cardholder Where PStatus='停车' And PCardtype='临时卡' And CarNo Like '%356%' Order By CarNo,PInTime //Select ID,CardID, PInTime from CprCardConsumeRecordTmp Where CardID='170119152243160' And PInTime='2017-01-19 15:22:43' //insert into CprCardConsumeRecordTmp (ID,Cardid,PInTime,TypeName,TypeTime,TypeMoney,ActionTime,Operator) values ('170119152243160','170119152243160','2017-01-19 15:22:43','内部优惠','120','0','2017-01-31 20:58:18','Administrator') Statement stmt; ResultSet rs = null; try { stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="Select ID,CardID, PInTime from CprCardConsumeRecordTmp Where CardID='170119152243160' And PInTime='2017-01-19 15:22:43'"; rs=stmt.executeQuery(sql); while(rs.next()) { System.out.println(rs.getString("CardID")); } rs.close(); stmt.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args){ new Main(); } }
上一篇:LINUX php mssql(odbc /pdo_dblib)
下一篇:汉王笔USB描述符