读书人

连结数据库异常

发布时间: 2012-02-08 19:52:21 作者: rapoo

连结数据库错误
问题在后面的那个数据库连结的地方try....catch...中

/*程序目标:
* Applet,
* 网页中加入本程序 <applet> </applet> ,显示企业的名片信息
* 参考名片形式:http://show.namepic.com/
*
* 过程:
* 1、获取页面的参数?userid
* 2、根据参数userid获取数据中的会员资料
* 3、绘图做出名片,显示提取的数据
* */
import java.lang.*;
import java.awt.*;

import java.sql.*;
import java.applet.*;

public class company_user_ecard extends Applet{
//声明一些属性
FontMetrics FM;
Color C,ColorBackground,NomalTextColor;
Font F,NomalTextFont;
int Ascent,Descent;
int AppletWidth,AppletHeight;

String Str ;
int StrWidth;
int PosiX,PosiY,PosiX2,PosiY2;

String UserID;
String[] UserInfos;


//初始化工作,定义背景颜色/通用文字的字体、颜色
public void init(){
ColorBackground = Color.BLACK;//enumc
NomalTextColor = Color.WHITE;
NomalTextFont = new Font( "Courier ",Font.BOLD,24);
AppletWidth = getSize().width;
AppletHeight = getSize().height;

//获取网页参数:用String,不考虑网页userid= 10 || a ;
UserID = getParameter( "userid ");
//System.out.print(UserID);
//return;
}

public void paint(Graphics g){
//AppletWidth = getSize().width;
//AppletHeight = getSize().height;
setNomalBackRect(g);


UserInfos = getUserInfo(UserID);
//txtCompanyName = String.valueOf(getUserInfo(UserID));
//String txtCompanyName = (String) String.valueOf(getUserInfo(UserID));
///int是原始数据类型 String是对象,所以要对原始数据对象化 //Mr.常 00:56:50


System.out.print(UserInfos[0]);
}

public void setNomalBackRect(Graphics g){

//背景 白色
setBackground(Color.WHITE);
//绘制边框
//第一个框 黑色
g.setColor(Color.black);
PosiX = 2;
PosiY = 2;
PosiX2 = AppletWidth-2*PosiX;
PosiY2 = AppletHeight-2*PosiY;
g.fillRect(PosiX,PosiY,PosiX2,PosiY2);


//第二个框 白色
PosiX = 3;
PosiY = 3;
PosiX2 = AppletWidth-2*PosiX;
PosiY2 = AppletHeight-2*PosiY;
g.setColor(Color.white);
g.fillRect(PosiX,PosiY,PosiX2,PosiY2);

//公司名称框
PosiX = 5;
PosiY = 5;
PosiX2 = AppletWidth-2*PosiX;
PosiY2 = AppletHeight-2*PosiY;
g.setColor(new Color(31,97,43)); //
g.fillRect(PosiX,PosiY,PosiX2,35);


//联系方式填充
PosiX = 5;
PosiY = 43;
PosiX2 = AppletWidth-2*PosiX;
PosiY2 = AppletHeight-48;
g.setColor(new Color(31,97,43)); //
g.fillRect(PosiX,PosiY,PosiX2,PosiY2);

//联系方式内填充
PosiX = 6;
PosiY = 44;
PosiX2 = AppletWidth-2*PosiX;
PosiY2 = AppletHeight-50;
g.setColor(new Color(112,209,129)); //
g.fillRect(PosiX,PosiY,PosiX2,PosiY2);

//绘制水印文字
Str = "阿龙空间 ";
g.setColor(new Color(255,255,255,128));
g.setFont(NomalTextFont);

FM = g.getFontMetrics();
StrWidth = FM.stringWidth(Str);
Ascent = FM.getAscent();
Descent = FM.getDescent();
PosiX = (AppletWidth-StrWidth-10);
PosiY = (AppletHeight);//-Ascent-Descent);

g.drawString(Str, PosiX, PosiY-10);

}

//数据库获取客户资料
//public static String[] getUserInfo(int userid)
public static String[] getUserInfo(String userid)


{
//需要返回的内容保存在数组中
String userinfo[] = new String[10];

//userinfo[0] = (String) Integer.toString(userid);
//String.valueOf 调用的其实是Integer.toString
//引入的参数

System.out.println(userid);

//加载驱动
try {
//java:JDBC-ODBC桥
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
}
/*catch(ClassNotFoundException e1){

System.err.println(e.getMessage());
ClassNotFoundException
}
*/

catch(Exception e){
System.out.println( "未能加载Jdbc-Odbc Bridge Driver ");
System.err.println( "ClassNotFoundException: ");
System.err.println( e.getCause()); // <--竟然返回的是null!
System.err.println(e.getMessage());
} //end jdbc-odbc bridge 's try

userinfo[0] = userid;

return userinfo;
}
}


[解决办法]
直接用JDBC不就行了,现在还有人用JDBC-ODBC桥吗?
[解决办法]
去这里看看吧:
http://www.javadingle.com

读书人网 >J2SE开发

热点推荐