class lx{
String sql;
Statement stmt;
Connection con;
BufferedReader bufferObj;
ResultSet rs;
public lx() {
bufferObj=new BufferedReader(new InputStreamReader(System.in));
}
public void establishConnection(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException ce){
System.out.print(ce.getMessage()) ;
}
try{
String url = "jdbc:odbc:producted";
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}catch(SQLException ce){
System.out.print(ce) ;
}
}
public void searchRecord(){
try{
System.out.print("\n请输入数量:") ;
int number=Integer.parseInt(bufferObj.readLine()) ;
sql="select * from Product where Quantity="+number;
rs=stmt.executeQuery(sql) ;
while(rs.next()){
System.out.print("\n产品代码:");
System.out.print(rs.getInt(1)+"\t") ;
System.out.print("\n产品名字:");
System.out.print(rs.getString(2)+"\t") ;
System.out.print("\n产品数量:");
System.out.print(rs.getString(3)+"\t") ;
System.out.println(" ") ;
}
}catch(SQLException ce){
System.out.print(ce) ;
}catch(Exception e){
System.out.print(e) ;
}
}
public void searchRecord1(){
try{
System.out.print("\n请输入产品代码:") ;
int a=Integer.parseInt(bufferObj.readLine()) ;
sql="select * from quest where ProductCode="+a;
rs=stmt.executeQuery(sql);
if(!rs.next() ){
System.out.print("\n查询失败") ;
}else{
System.out.print("\n产品代码:");
System.out.print(rs.getInt(1)+"\t") ;
System.out.print("\n产品名字:");
System.out.print(rs.getString(2)+"\t") ;
System.out.print("\n产品数量:");
System.out.print(rs.getString(3)+"\t") ;
System.out.println(" ") ;
}
}catch(SQLException ce){
System.out.print(ce);
}catch(Exception e){
System.out.print(e);
}
}
public void display()throws IOException{
char choice;
while(true){
System.out.println() ;
System.out.print("1.根据产品代码进行搜索") ;
System.out.println("2.根据数量进行搜索") ;
System.out.println("3.退出\n\n") ;
System.out.println("请输入你的选择....:") ;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
choice=(char)br.read();
switch(choice){
case'1':
System.out.println("\n请按数量进行搜索");
searchRecord();
break;
case'2':
System.out.println("\n 请按产品代码进行搜索") ;
searchRecord1();
break;
case'3':
System.exit(0) ;
break;
default:
System.out.println("\n请输入一个有效数字") ;
break;
}
}
}}
public class lxtext{
public lxtext(){
}
public static void main(String[] args) throws Exception{
lx lxobj = new lx();
lxobj.display();
}
}
String sql;
Statement stmt;
Connection con;
BufferedReader bufferObj;
ResultSet rs;
public lx() {
bufferObj=new BufferedReader(new InputStreamReader(System.in));
}
public void establishConnection(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException ce){
System.out.print(ce.getMessage()) ;
}
try{
String url = "jdbc:odbc:producted";
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}catch(SQLException ce){
System.out.print(ce) ;
}
}
public void searchRecord(){
try{
System.out.print("\n请输入数量:") ;
int number=Integer.parseInt(bufferObj.readLine()) ;
sql="select * from Product where Quantity="+number;
rs=stmt.executeQuery(sql) ;
while(rs.next()){
System.out.print("\n产品代码:");
System.out.print(rs.getInt(1)+"\t") ;
System.out.print("\n产品名字:");
System.out.print(rs.getString(2)+"\t") ;
System.out.print("\n产品数量:");
System.out.print(rs.getString(3)+"\t") ;
System.out.println(" ") ;
}
}catch(SQLException ce){
System.out.print(ce) ;
}catch(Exception e){
System.out.print(e) ;
}
}
public void searchRecord1(){
try{
System.out.print("\n请输入产品代码:") ;
int a=Integer.parseInt(bufferObj.readLine()) ;
sql="select * from quest where ProductCode="+a;
rs=stmt.executeQuery(sql);
if(!rs.next() ){
System.out.print("\n查询失败") ;
}else{
System.out.print("\n产品代码:");
System.out.print(rs.getInt(1)+"\t") ;
System.out.print("\n产品名字:");
System.out.print(rs.getString(2)+"\t") ;
System.out.print("\n产品数量:");
System.out.print(rs.getString(3)+"\t") ;
System.out.println(" ") ;
}
}catch(SQLException ce){
System.out.print(ce);
}catch(Exception e){
System.out.print(e);
}
}
public void display()throws IOException{
char choice;
while(true){
System.out.println() ;
System.out.print("1.根据产品代码进行搜索") ;
System.out.println("2.根据数量进行搜索") ;
System.out.println("3.退出\n\n") ;
System.out.println("请输入你的选择....:") ;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
choice=(char)br.read();
switch(choice){
case'1':
System.out.println("\n请按数量进行搜索");
searchRecord();
break;
case'2':
System.out.println("\n 请按产品代码进行搜索") ;
searchRecord1();
break;
case'3':
System.exit(0) ;
break;
default:
System.out.println("\n请输入一个有效数字") ;
break;
}
}
}}
public class lxtext{
public lxtext(){
}
public static void main(String[] args) throws Exception{
lx lxobj = new lx();
lxobj.display();
}
}
public lxtext(){
}
public static void main(String[] args) throws Exception{
lx lxobj = new lx();
lxobj.display();
}
}这个你放在了lx里面了
2.根据产品代码进行搜索3.退出
请输入你的选择....:
1请按数量进行搜索请输入数量:80产品代码:java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]对于造型说明无效的字符值
1.根据数量进行搜索
2.根据产品代码进行搜索3.退出
请输入你的选择....:
错误代码
就是不能显示啊
什么原因