📄 database.java
字号:
/*
* Database.java
*
* Created on 2007年12月26日, 上午8:45
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package book;
import book.*;
import java.sql.*;
import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.JTable;
public class Database {
Connection con;
Statement stmt;
ResultSet rs;
public Database() { }
public String link() {
String rturn="";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:qs");
stmt=con.createStatement();
rturn="y";
} catch(Exception e){
JOptionPane.showMessageDialog(null,"链接出错");
rturn=e.toString();
}
return rturn;
}
public void cutlink() {
try{
if(con!=null){
con.close();
con=null;
}
}
catch(Exception e){}
}
public ResultSet getResult(String sql){
try{
rs=stmt.executeQuery(sql);
return rs;
}catch(SQLException e){
return null;
}
}
public String add_book(String[] add){
String f="";
try{
link();
String sql="select count(*) from book_jbxx";
rs=stmt.executeQuery(sql);
rs.next();
if(rs.getInt(1)>0){
sql="select max(*) from book_jbxx";
rs=getResult(sql);
}
sql="insert into book_jbxx values ('"+add[0]+"','"+add[1]+"','"+add[2]+"','"+add[3]+"','"+add[4]+"','"+add[5]+"')";
stmt.execute(sql);
f="y";
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"没有此分类!"+f);
}
finally{
cutlink();
}
return f;
}
public static void main(String[] args) {
String s="";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:qs");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from book_classify");rs.close();
stmt.close();
con.close();
//System.out.println("----------------------------------------");测试语句
}catch(ClassNotFoundException e){
System.out.println(""+e.toString());
System.out.println("Nofound");
}catch(SQLException e){
System.out.println("SQL error:"+e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -