W
weiiguo
Unregistered / Unconfirmed
GUEST, unregistred user!
下面一个用JDK写的JAVA程序,不知道怎么看不到结果数据。
源码如下:
import java.awt.*;
import java.applet.*;
import java .sql.*;
import java.io.*;
import java.net.*;
public class DbApplet1 extends Applet
{ public void init()
{ resize(400,300);
}
public void paint(Graphics g) //此方法用于显示输出
{ this.setBackground(Color.lightGray );
//定义背景颜色
this.setForeground(Color.red);
//定义前景颜色
String url="jdbcdbc:HrDb";
String ls_1="select jb004,jb001,jb005 from ryjb";
//异常处理模块
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//加载驱动程序
//建立连接
Connection con=DriverManager.getConnection(url,"sa","sa");
//执行SQL
Statement stmt=con.createStatement();
ResultSet result=stmt.executeQuery(ls_1);
//返回结果
g.drawString("姓名",40,40);
g.drawString("编号",120,40);
g.drawString("部门",200,40);
int i=10;
while(result.next())
{ //取各个字段的值
g.drawString(result.getString("jb004"),40,60+i);
g.drawString(result.getString("jb001"),80,60+i);
g.drawString(result.getString("jb005"),160,60+i);
i+=20;
}
//关闭连接
result.close();
stmt.close();
con.close();
}
//捕获异常
catch(SQLException e){System.out.println("连接数据库时出错:"+e.getMessage());}
catch(java.lang.ClassNotFoundException e){System.out.println("加载数据库驱动时出错:"+e.getMessage());
}
}
}
源码如下:
import java.awt.*;
import java.applet.*;
import java .sql.*;
import java.io.*;
import java.net.*;
public class DbApplet1 extends Applet
{ public void init()
{ resize(400,300);
}
public void paint(Graphics g) //此方法用于显示输出
{ this.setBackground(Color.lightGray );
//定义背景颜色
this.setForeground(Color.red);
//定义前景颜色
String url="jdbcdbc:HrDb";
String ls_1="select jb004,jb001,jb005 from ryjb";
//异常处理模块
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//加载驱动程序
//建立连接
Connection con=DriverManager.getConnection(url,"sa","sa");
//执行SQL
Statement stmt=con.createStatement();
ResultSet result=stmt.executeQuery(ls_1);
//返回结果
g.drawString("姓名",40,40);
g.drawString("编号",120,40);
g.drawString("部门",200,40);
int i=10;
while(result.next())
{ //取各个字段的值
g.drawString(result.getString("jb004"),40,60+i);
g.drawString(result.getString("jb001"),80,60+i);
g.drawString(result.getString("jb005"),160,60+i);
i+=20;
}
//关闭连接
result.close();
stmt.close();
con.close();
}
//捕获异常
catch(SQLException e){System.out.println("连接数据库时出错:"+e.getMessage());}
catch(java.lang.ClassNotFoundException e){System.out.println("加载数据库驱动时出错:"+e.getMessage());
}
}
}