java应怎样连接数据库?
java连接数据库查询,怎么一直在报这个错误import java.sql.*;
public class chaxun {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成的方法存根
Query query=new Query();
String dateSource="myDate";
String tableName="goods";
query.setDatesourceName(dateSource);
query.setTableName(tableName);
String number="A001";
String SQL="SELECT*FROM"+tableName+"WHERE number='"+number+"'";
query.setSQL(SQL);
System.out.println(tableName+"表中商品号是"+number+"记录号");
query.inputQueryResult();
double max=300000,min=260000;
SQL="SELECT*FROM"+tableName+"WHERE PRICE>="+min+"AND price<="+max;
query.setSQL(SQL);
System.out.println(tableName+"表中价格在"+min+"之间的记录:");
query.inputQueryResult();
String SQL1="SELECT*FROM"+tableName+"ORDER BY name";
query.setSQL(SQL1);
System.out.println(tableName+"表记录按商品名称排序:");
query.inputQueryResult();
SQL1="SELECT*FROM"+tableName+"ORDER BY price";
query.setSQL(SQL);
System.out.println(tableName+"表记录按商品价格排序:");
query.inputQueryResult();
String SQL11="SELECT*FROM"+tableName+"WHERE name LIKE '%[电箱]%'";
query.setSQL(SQL11);
System.out.println(tableName+"表中商品名称有“T”或“宝”的记录:");
query.inputQueryResult();
}
}
Exception in thread "main" java.lang.NullPointerException
at Query.setSQL(Query.java:20)
at chaxun.main(chaxun.java:18)