/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package newpackage;
/**
*
* @author Administrator
*/
import java.sql.*;
public class BookMesg {
public static void main(String [] args){//建造书的相关信息的表
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(Exception e) {
System.out.println("Can't load JDBC Driver. " +
"Make sure classpath is correct");
return;
}
String url = "jdbc:microsoft:sqlserver://localhost:1433";
String booksign1 = "sa";
String bookcode1 = "";
Connection connection1;
try {
connection1 = DriverManager.getConnection(url, booksign1,bookcode1);
}
catch (SQLException e) {
System.out.println("Connect problem: " + e.getMessage());
return;
}
try{
Statement statement1 = connection1.createStatement();
/*在这下面加代码*/
statement1.executeUpdate(
" create table bookmesge("+
" bookno char(30) primary key," +
" booktype char(10)," +
" bookname char(20)," +
" bookprice int," +
" bookauthor char(10)," +
" bookpublic char(20),"+
" bookicon char(40)," +
" bookptime char(12)," +
" bookcontent char(200))");
System.out.println("--Insert Data--");
statement1.executeUpdate(
"insert into bookmesge(bookno,booktype,bookname,bookprice,bookauthor,bookpublic,bookicon,bookptime,bookcontent) values"+
" ('rmxsfgnndsj','热门新书','梵高奶奶的世界',16,'江华','中信出版社','rmxsfgnnesj.jpg','05/07/2009','一部温情之书。一颗清澈干净的心。在她的画里,色彩就是感情,线条勾勒的全是记忆。她70多才开始绘画,却被人们称之为“中国农村的梵高”。')");
statement1.executeUpdate(
"insert into bookmesge(bookno,booktype,bookname,bookprice,bookauthor,bookpublic,bookicon,bookptime,bookcontent) values"+
" ('wxdxflqm','文学','当幸福来敲门',19,'加德纳','清华大学出版社','wxdxflqm.jpg','04/04/2009','《当幸福来敲门》是美国著名黑人投资专家克里斯·加德纳生平的真实写照,他用生命诠释了责任和奋斗以及如何去实现梦想,永不放弃梦想,永远奋力前行。')");
statement1.executeUpdate(
"insert into bookmesge(bookno,booktype,bookname,bookprice,bookauthor,bookpublic,bookicon,bookptime,bookcontent) values"+
" ('kjdx','科技','大象',53,'谭云杰','中国水利水电出版社','kjdxjpg','08/23/2009','以UML为载体,将面向对象的分析设计思想巧妙地融入建模过程中,通过贯穿全书的实例将软件系统开发过程中方方面面的知识有机地结合在一起。')");
}
catch(SQLException e){
System.out.println("An SQLException occurred :" + e.getMessage());
}
catch(Exception e){
e.printStackTrace(System.err);
}
}
public static int checkprice(String bookno1)//取得该书的价格
{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(Exception e) {
System.out.println("Can't load JDBC Driver. " +
"Make sure classpath is correct");
}
String url = "jdbc:microsoft:sqlserver://localhost:1433";
String booksign2 = "sa";
String bookcode2 = "";
Connection connection2 = null;
try {
connection2 = DriverManager.getConnection(url,booksign2,bookcode2);
}
catch (SQLException e) {
System.out.println("Connect problem: " + e.getMessage());
}
try{
Statement statement2 = connection2.createStatement();
String sql="select bookprice from bookmesge where bookmesge.bookno ='"+bookno1+"'";
ResultSet rs2;
rs2=statement2.executeQuery(sql);
rs2.next();
int price=rs2.getInt("bookprice");
return price;
}
catch(SQLException e){
System.out.println("An SQLException occurred :" + e.getMessage());
}
catch(Exception e){
e.printStackTrace(System.err);
}
return 0;
}
public static String checkname(String bookno1)//取得该书的名字
{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(Exception e) {
System.out.println("Can't load JDBC Driver. " +
"Make sure classpath is correct");
}
String url = "jdbc:microsoft:sqlserver://localhost:1433";
String bookcode3 = "sa";
String booksign3 = "";
Connection connection3 = null;
try {
connection3 = DriverManager.getConnection(url, booksign3, bookcode3);
}
catch (SQLException e) {
System.out.println("Connect problem: " + e.getMessage());
}
try{
Statement statement3 = connection3.createStatement();
String sql="select bookname from bookmesge where bookmesge.bookno ='"+bookno1+"'";
ResultSet rs3;
rs3=statement3.executeQuery(sql);
rs3.next();
String name=rs3.getString("bookname");
return name;
}
catch(SQLException e){
System.out.println("An SQLException occurred :" + e.getMessage());
}
catch(Exception e){
e.printStackTrace(System.err);
}
return null;
}
public static String checkauthor(String bookno1)//取得该书作者的名字
{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(Exception e) {
System.out.println("Can't load JDBC Driver. " +
"Make sure classpath is correct");
}
String url = "jdbc:microsoft:sqlserver://localhost:1433";
String booksign4 = "sa";
String bookcode4 = "";
Connection connection4 = null;
try {
connection4 = DriverManager.getConnection(url,booksign4,bookcode4);
}
catch (SQLException e) {
System.out.println("Connect problem: " + e.getMessage());
}
try{
Statement statement4 = connection4.createStatement();
String sql="select bookauthor from bookmesge where bookmesge.bookno ='"+bookno1+"'";
ResultSet rs4;
rs4=statement4.executeQuery(sql);
rs4.next();
String author=rs4.getString("bookauthor");
return author;
}
catch(SQLException e){
System.out.println("An SQLException occurred :" + e.getMessage());
}
catch(Exception e){
e.printStackTrace(System.err);
}
return null;
}
public static String checkpublic(String bookno1)//取得出版该书的出版社
{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(Exception e) {
System.out.println("Can't load JDBC Driver. " +
"Make sure classpath is correct");
}
String url = "jdbc:microsoft:sqlserver://localhost:1433";
String booksign5 = "sa";
String bookcode5 = "";
Connection connection5 = null;
try {
connection5 = DriverManager.getConnection(url, booksign5, bookcode5);
}
catch (SQLException e) {
System.out.println("Connect problem: " + e.getMessage());