?? mybean.java
字號:
package com.junit;
import java.sql.*;
import java.io.*;
public class MyBean{
Statement stmt=null;
ResultSet rs=null;
Connection conn=null;
String result=null;
public String con(){ //初始化數(shù)據(jù)庫
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/buy";
conn= DriverManager.getConnection(url,"root","1111");
return "Connection Success!";
}
catch(Exception e){
System.out.println(e);
return "Connection Error!";
}
}
public String gogo(int lmdm){ //查詢數(shù)據(jù)庫
try{
stmt=conn.createStatement();
String sql="select * from consume where CONSUMEID='"+lmdm+"'";
rs=stmt.executeQuery(sql); //執(zhí)行查詢
while (rs.next()){
result=rs.getString("PRICE");
}
}
catch(Exception e){
result=e.toString();
}
finally { //關(guān)閉JDBC資源
if(rs != null) try { rs.close(); } catch(SQLException ex) { ex.printStackTrace(); }
if(conn != null) try { conn.close(); } catch(SQLException ex) { ex.printStackTrace(); }
}
return result;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -