📄 sqlresultset.java
字号:
/*
* SQLResultSet.java
*
* Created on 2007年3月2日, 下午2:57
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package XRSystem.DataAccess;
import java.util.*;
import java.lang.*;
import java.sql.*;
/**
*
* @author 王刚
*/
public class SQLResultSet {
/** Creates a new instance of SQLResultSet */
public SQLResultSet() {
}
private java.sql.Connection con = null;
private final String url = "jdbc:microsoft:sqlserver://";
private final String serverName= "localhost";
private final String portNumber = "1433";
private final String databaseName= "XR_System";
private final String userName = "sa";
private final String password = "83833224";
private final String selectMethod = "cursor";
private int DocumentID;
private String getConnectionUrl() {
//serverName=JOptionPane.showInputDialog("请输入数据库名称:");
return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";"; }
private java.sql.Connection getConnection() {
try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String TempUrl= getConnectionUrl();
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
if(con!=null)
System.out.println("成功连接数据库:"+databaseName); } catch(Exception e) {
e.printStackTrace();
System.out.println("跟踪在方法getConnection()出现的错误 : " + e.getMessage()); }
return con; }
private void closeConnection() {
try {
if(con!=null)
con.close();
con=null; } catch(Exception e){ e.printStackTrace(); }
}
public void ExecuteInsert(String InsertSQL) throws Exception {
int flag;
try{con= this.getConnection();
if(con!=null) {
PreparedStatement pstmt = con.prepareStatement(InsertSQL,ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
flag = pstmt.executeUpdate();
if(flag!=0)
System.out.print("数据已写入数据库!");
}
closeConnection();
}catch(Exception e){ e.printStackTrace(); }
}
public ResultSet ExecuteSQL(String SQLString) {
ResultSet rs = null;
try{con= this.getConnection();
if(con!=null) {
PreparedStatement pstmt = con.prepareStatement(SQLString,ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = pstmt.executeQuery();
}
//closeConnection();
}catch(Exception e){ e.printStackTrace(); }
return rs;
}
public int GetDocID(String SQLString)
{
int DocID=0;
return DocID;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -