freetkh
发贴: 0
积分: 0
|
于 2003-08-29 08:30
我用了下面的程序是能操作数据库,但不知道怎么配置weblogic.
package tkh.jdbc.dbmaker;
//import javax.swing.*; import java.sql.*; import java.io.*; import java.util.*; import dbmaker.sql.*;
public class DataAccess// extends JApplet { private String dbName=""; private String userId=""; private String userPwd=""; private Connection cnn=null; private String driver="dbmaker.sql.JdbcOdbcDriver";
public static void main(String[] args) { DataAccess app=new DataAccess("DBSAMPLE4","SYSADM",""); }
public DataAccess(String db,String id,String pwd) { dbName=db; userId=id; userPwd=pwd; if(beginConnect()==0) return; readData("allType"); }
private int beginConnect() { try { prt("注册驱动:\n"); Class.forName(driver).newInstance(); } catch(Exception e) { prt("数据驱动注册出错:\n"); prt("Message:"+e.getMessage()); e.printStackTrace(); return 0; } try { //DriverManager.registerDriver(new dbmaker.sql.JdbcOdbcDriver()); prt("连接数据库:\n"); cnn=DriverManager.getConnection("jdbc:dbmaker:"+dbName,userId,userPwd); return 1; } catch(SQLException e) { prt("连接dbmaker数据库出错:\n"); //while(e!=null) //{ prt("Message:"+e.getMessage()); //e=e.getNextException(); e.printStackTrace(); prt(" "); //} cnn=null; return 0; } }
public void readData(String tableName) { try { Statement stmt=cnn.createStatement(); ResultSet rs=stmt.executeQuery("select * from "+tableName); ResultSetMetaData rsmd=rs.getMetaData(); int cols=rsmd.getColumnCount(); int i=0; prt("共有:"+cols+"列。"); for(i=0;i<cols;i++) { prt("列:"+i);//Stringrsmd.getColumnName()+"\t"); } prt(" "); } catch(Exception e) { prt("数据读取错误:\n"); prt(e.getMessage()); e.printStackTrace(); } }
private void prt(String s) { System.out.println; } }
|