📄 access.java
字号:
/*
* Created on 2004-5-25
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.sql.*;
public class Access
{
private String DriverStr="sun.jdbc.odbc.JdbcOdbcDriver";
private String ConStr="jdbc:odbc:student";
private static Connection con=null;
private static Access access=null;
private static Statement stmt=null;
private Access(){
try
{
Class.forName(DriverStr);
con=DriverManager.getConnection(ConStr,"","");
}
catch (java.lang.ClassNotFoundException e)
{
System.out.println(e.toString());
}
catch (java.sql.SQLException e){
System.out.println(e.toString());
}
}
public static Access getAccess()
{
if(access==null) access=new Access();
return access;
}
public void closeConnection()
{
try
{
con.close();
stmt.close();
}
catch(Exception ex){}
}
public ResultSet execQuery(String sql) throws SQLException {
ResultSet rs=null;
try
{
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
}
catch (SQLException ex)
{
throw ex;
}
return rs;
}
public void execUpdate(String sql) throws SQLException {
try
{
con=DriverManager.getConnection(ConStr);
Statement stmt=con.createStatement();
stmt.executeUpdate(sql);
}
catch (SQLException ex)
{
throw ex;
}
}
public void execPreparedStatement(String preparedSQL,String[] args) throws Exception
{
try {
PreparedStatement pstmt=con.prepareStatement(preparedSQL);
for(int i=1;i<=args.length;i++)
{
pstmt.setString(i,args[i]);
}
pstmt.execute();
}
catch (Exception ex) {
throw ex;
}
}
public static void main(String args[]){
Access d=Access.getAccess();
try{
d.execUpdate("INSERT INTO student(studentPassword,studentNumber) VALUES('jackson','11')" );
}
catch(Exception e) { System.out.println(e); }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -