求助:javabean里重新链接数据库后建表抛出
java.lang.NullPointerException我的问题如下:在一个数据库里查到相关数据库后,重新链接另外的数据库建立数据库表。但总是出现
空指针错误的问题。而这个建表操作放在第一个链接的数据库里进行却成功执行。请教各位了
代码如下。
package com;
import java.sql.*;
import common.sqldatabase;
public class createtb {
public createtb() {
}
public boolean createtable(String table, String dbname) throws
ClassNotFoundException,
SQLException {
String tname = table;
ResultSet rs = null;
sqldatabase sqlcon = new sqldatabase();
sqldatabase sqlcon2 = new sqldatabase();
String colname = new String();
String coltype = new String();
String db = dbname;
//System.out.println(db);
boolean i=false;
StringBuffer sqls = new StringBuffer();
int collen;
//String sqla= "use "+db;
//String sqlb= ";
String sql1 = " ";
String sqlstr = "CREATE TABLE dbo. " + tname + "(wwid varchar(20) NOT NULL,wwmch varchar
(20),wwlx varchar(20),wwsd varchar(20),wwcflj varchar(50),wwcd varchar(50),wwds varchar
(100) ";
String sql2 = "select * from columtable where tablename= ' " + tname + " ' ";
sqls.append(sqlstr);
try {
//sqlcon.setDatabaseName(db);
sqlcon.getCon();
rs = sqlcon.query(sql2);
if(!rs.next()){ sqls.append( ") ");}
//获取并构造数据库语句
while (rs.next()) {
colname = rs.getString( "columname ");
coltype = rs.getString( "columtype ");
collen = rs.getInt( "columlen ");
sqls.append( ", ");