求jsp连接数据库的javabean代码
javabean里有俩个方法executeUpdateexecuteQuery可以实现简单的对数据库进行增删改查的操作的那种。连接的是mysql数据库...
javabean里有俩个方法
executeUpdate
executeQuery
可以实现简单的对数据库进行增删改查的操作的那种。
连接的是mysql数据库 展开
executeUpdate
executeQuery
可以实现简单的对数据库进行增删改查的操作的那种。
连接的是mysql数据库 展开
1个回答
展开全部
import java.sql.*;
class Access {
Connection con;
Statement stt;
ResultSet rs;
void begin(){
if (con!=null||stt!=null){
this.closs();
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try{
con=DriverManager.getConnection("jdbc:odbc:Wang","","");
stt=con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ResultSet qu(String sql) throws SQLException{
this.begin();
return stt.executeQuery(sql);
}
public boolean cun(String sql) throws SQLException{
this.begin();
return stt.execute(sql);
}
public void closs()
{
try {
stt.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
public static void main(String args[]){
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.println(""+e);
}
try{
con=DriverManager.getConnection("jdbc:odbc:Wang","","");
sql=con.createStatement();
rs=sql.executeQuery("Select * FROM expert");
con.createStatement();
while(rs.next())
{
One.a=rs.getInt(2);
int b=rs.getInt(3);
One.b=b;
One experts=new One();
experts.setC(One.b);
System.out.println("a:"+One.a);
System.out.println("b:"+experts.getC());
}
con.close();
}
catch(SQLException el)
{
el.printStackTrace();
}
}
*/
剩下的功能应该会写了吧?呵呵
我只用到取数据 和 存数据。
class Access {
Connection con;
Statement stt;
ResultSet rs;
void begin(){
if (con!=null||stt!=null){
this.closs();
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try{
con=DriverManager.getConnection("jdbc:odbc:Wang","","");
stt=con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ResultSet qu(String sql) throws SQLException{
this.begin();
return stt.executeQuery(sql);
}
public boolean cun(String sql) throws SQLException{
this.begin();
return stt.execute(sql);
}
public void closs()
{
try {
stt.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
public static void main(String args[]){
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.println(""+e);
}
try{
con=DriverManager.getConnection("jdbc:odbc:Wang","","");
sql=con.createStatement();
rs=sql.executeQuery("Select * FROM expert");
con.createStatement();
while(rs.next())
{
One.a=rs.getInt(2);
int b=rs.getInt(3);
One.b=b;
One experts=new One();
experts.setC(One.b);
System.out.println("a:"+One.a);
System.out.println("b:"+experts.getC());
}
con.close();
}
catch(SQLException el)
{
el.printStackTrace();
}
}
*/
剩下的功能应该会写了吧?呵呵
我只用到取数据 和 存数据。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询