DataBase.java
~~~
package zyw.tools;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class DataBase {
public static void main(String[] args)
{
PreparedStatement ps=null;
Connection ct=null;
ResultSet rs=null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://127.0.0.1:3306/books";
ct = DriverManager.getConnection(url, "root", "123456");
ps=ct.prepareStatement("select * from book where BookNo=? or didian=?");
rs=ps.executeQuery();
while(rs.next())
{
int bianhao=rs.getInt(1);
String mingcheng=rs.getString(2);
String didian=rs.getString(3);
System.out.println(bianhao+" "+mingcheng+" "+didian);
}
// ps=ct.prepareStatement("insert into bumen values(?,?,?)");
// ps.setInt(1,7); ps.setString(2,"侦查"); ps.setString(3,"山外");
rs=ps.executeQuery();
} catch (Exception e){}
finally
{
try {
if(rs!=null)
{
rs.close();
}
if(ps!=null)
{
ps.close();
}
if(ct!=null)
{
ct.close();
}
} catch (Exception e){}
}
}
}
~~~