谁有java模糊查询的完整代码啊,给看下呗!
2个回答
展开全部
import java.sql.*;
public class TestSql {
public static void main(String[] args) {
Connection conn;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jbdc.obdc.JdbcOdbcDriver");
}catch(ClassNotFoundException e){
}
try{
conn=DriverManager.getConnection("jdbc:odbc:sun","xiao","123");
sql=conn.createStatement();
rs=sql.executeQuery("select name,math from chengjibiao where name like'_淑%'");
while(rs.next()){
String name=rs.getString(1);
int math = rs.getInt(2);
System.out.println("姓名:"+name);
System.out.println("数学:"+math);
}
conn.close();
}catch(SQLException e){
System.out.println(e);
}
}
}
//%代表0个或多个,_代表一个
public class TestSql {
public static void main(String[] args) {
Connection conn;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jbdc.obdc.JdbcOdbcDriver");
}catch(ClassNotFoundException e){
}
try{
conn=DriverManager.getConnection("jdbc:odbc:sun","xiao","123");
sql=conn.createStatement();
rs=sql.executeQuery("select name,math from chengjibiao where name like'_淑%'");
while(rs.next()){
String name=rs.getString(1);
int math = rs.getInt(2);
System.out.println("姓名:"+name);
System.out.println("数学:"+math);
}
conn.close();
}catch(SQLException e){
System.out.println(e);
}
}
}
//%代表0个或多个,_代表一个
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询