import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class testdb {
public static String connect(String uid,String upass)
{
String reflag = "0";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");//要匯入外部包
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:scott/tiger@localhost:1522:stuf1dbsid");//最後//一個是oracle的sid號
//stuf1dbsid sid號 scott/tiger登陸 sql為sql命令串 logondb為表 表有userid upass
// sql句子 為 select * from logindb where userid='uid' and upass='upass' ""不顯示 ''才顯示 ''是sql語句中框變數的
String sql="select * from login where sname='" + uid + "'and pass='" + upass+ "'";//定義
// result
PreparedStatement psmt= conn.prepareStatement(sql); //
ResultSet res = psmt.executeQuery();
//String a=res.getString(uid);
//System.out.println(a);
if(res.next())
{
reflag="1";
// System.out.println(res.getString(1));
// System.out.println(res.getString(2));
// res.getString(1);
// System.out.println("login ok");
//TestDia t= new TestDia(null);
//t.setVisible(true);
}else
{
System.out.println("login error");
}
} catch (ClassNotFoundException e1) {
// TODO 帺?惗惉 catch ?
System.out.println("login 2");
}
catch (SQLException e1) {
// TODO 帺?惗惉 catch ?
System.out.println("login 3");
}
return reflag;
}
public static String connectedb(String uname,int i )
{
String ret="";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:scott/tiger@localhost:1522:stuf1dbsid");
String sql="select * from T_USER where USERNAME='"+uname+"'";
PreparedStatement psmt= conn.prepareStatement(sql); //
ResultSet res = psmt.executeQuery();
if(res.next()){
ret=res.getString(i);
//if(uname!=res.getString(2)){
// JOptionPane.showMessageDialog(null, "查詢失敗"); }
}
else{
System.out.println("login 1");
//JOptionPane.showMessageDialog(null, "查詢失敗");
}
} catch (SQLException e) {
System.out.println("login 2");
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e1) {
System.out.println("login 3");
// TODO Auto-generated catch block
e1.printStackTrace();
}
return ret;
}
//
// public static void main(String[] args) {
//
//
//
//
//
//
// }
}