?? link.java~42~
字號:
?
+
package supermarket;
//SQL連接類
import java.sql.*;
import javax.swing.*;
public class Link {
public Link() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
Connection con = null; //連接
Statement s = null; //Statement
ResultSet rs = null; //結果集
int count = 0;
public void connection() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=supermarket;","sa","sa");
s = con.createStatement();
}
catch (ClassNotFoundException ex) {
}
catch (SQLException ex) {
/** @todo Handle this exception */
}
}
public void close() {
try {
if (rs != null) { //關閉結果集
rs.close();
}
if (s != null) {
s.close(); //關閉Statement
}
con.close(); //關閉連接
}
catch (SQLException ex) {
}
}
public ResultSet Select(String sql) { //查詢方法
System.out.println(sql);
try {
rs = s.executeQuery(sql);
// MainFrm mf = new MainFrm();
return rs;
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "出錯啦!", "錯誤",
JOptionPane.ERROR_MESSAGE);
//ex.printStackTrace();
}
return rs;
}
private void jbInit() throws Exception {
}
public int Update(String sql) {
System.out.println(sql);
try {
count = s.executeUpdate(sql);
return count;
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "操作失敗", "錯誤",
JOptionPane.ERROR_MESSAGE);
// return;
}
return 0;
}
/**
* Select
*/
public void Select() {
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -