JDBC connection MSSQL

xiaoxiao2021-03-06  52

Package WAP;

Import java.io. *; import java.sql. *;

public class jdbc {String strconn = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = setop"; String strDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; Connection conn = null; Statement stmt = null; ResultSet RS = null; public java.sql.connection jdbc () {file: // connection try {class.forname (striver) .newinstance (); conn = drivermanager.getConnection (StrConn, "SA", ","); STMT = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_read_only);

} Catch (Exception E) {E.PrintStackTrace (); System.out.Println ("Error");} Return CONN;}

public ResultSet executeQuery (String sql) {file: // select try {conn = DriverManager.getConnection (strconn, "sa", ""); stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt. ExecuteQuery (SQL);} catch (sqlexception ex) {system.err.println ("Execute SQL statement error SELECT:" EX.GETMESSAGE ();} Return Rs;}

public ResultSet executeUpdate (String sql) {file: // insert, update try {conn = DriverManager.getConnection (strconn, "sa", ""); stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = Stmt.executeQuery (SQL);} catch (sqlexception ex) {system.err.println ("Execute SQL statement error insert, update:" ex.getMessage ());} RETURN RS;}

Public void closstmt () {file: // close statementTry {stmt.close ();} catch (sqlexception e) {E.PrintStackTrace ();}}

Public void closeconn () {file: // close connectionTry {conn.close ();} catch (sqlexception e) {E.PrintStackTrace ();}}}

转载请注明原文地址:https://www.9cbs.com/read-113216.html

New Post(0)