shiyan1连接oracle数据库试验

来源:互联网 发布:淘宝出售可非大力小泰 编辑:程序博客网 时间:2024/06/06 01:51
package ccwp;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class shiyan1 {
private static String db_config="db_config.properties";
public static String DRIVERS=null;
public static String USER=null;
public static String URL=null;
public static String PASSWORD=null;
public static  long V_WAYBILLNO2;


static{
Properties props=new Properties();
InputStream inStr=null;
try{
inStr=ClassLoader.getSystemResourceAsStream(db_config);
props.load(inStr);
}catch (IOException e){
e.printStackTrace();
}
DRIVERS=props.getProperty("drivers");
URL=props.getProperty("url");
USER=props.getProperty("user");
PASSWORD=props.getProperty("pwd");
}

public static Connection getConnection(){
Connection con = null;
 try{   
   con =  DriverManager.getConnection(URL , USER , PASSWORD ) ;   
    }catch(SQLException se){   
   System.out.println("数据库连接失败!");   
   se.printStackTrace() ;   
    } 
 return con;}
/**
* @param args
*/
public static void main(String[] args) {
Connection con = getConnection();
Statement statement = null;
String sql0=null;
long V_WAYBILLNO_long=0;
  String V_WAYBILLNO="";
// TODO Auto-generated method stub
try {
 
statement=con.createStatement();
sql0="select max(t.waybill_no) max_no from tt_bar_record t where t.waybill_no like '723%'";
ResultSet result = statement.executeQuery(sql0);
while(result.next()){
V_WAYBILLNO_long=result.getLong("max_no");
}
V_WAYBILLNO_long=V_WAYBILLNO_long+1;
V_WAYBILLNO=String.valueOf(V_WAYBILLNO_long);

//System.out.println(V_WAYBILLNO_long);//打印出要测试的运单号
System.out.println(V_WAYBILLNO);//打印出要测试的运单号
}
catch (SQLException e) {
e.printStackTrace();
}


}
public String receive_Bno(){
Connection con = getConnection();
Statement statement = null;
String sql0=null;
long V_WAYBILLNO_long=0;
  String V_WAYBILLNO="";
// TODO Auto-generated method stub
try {
 
statement=con.createStatement();
sql0="select max(t.waybill_no) max_no from tt_bar_record t where t.waybill_no like '723%'";
ResultSet result = statement.executeQuery(sql0);
while(result.next()){
V_WAYBILLNO_long=result.getLong("max_no");
}
V_WAYBILLNO_long=V_WAYBILLNO_long+1;
V_WAYBILLNO=String.valueOf(V_WAYBILLNO_long);

//System.out.println(V_WAYBILLNO_long);//打印出要测试的运单号
System.out.println(V_WAYBILLNO);//打印出要测试的运单号
}
catch (SQLException e) {
e.printStackTrace();
}
   return V_WAYBILLNO;
}
}
0 0
原创粉丝点击