检查一下这段代码有何问题/
import java.io.BufferedReader;
import java.io.IoException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;public class DBDemo {
private String strurl = "jdbc:odbc:book";
private connection conn = null;private Statement pstmt = null;private String getconsoleInput () {
String str = "";
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
try {
str = br.readLine();
} catch (IoException e) {
e.printStackTrace();
}
return str;
} public void ren() {
try {
getConnection();
while (true) {
System.out.println("<--请输入学生信息-->");
ValueObject vo = getInfo();
System.out.println("<--输入的学生信息如下-->");
System.out.println(vo);
System.out.println("<--正在保存数据,请稍候...-->");
save(vo);
System.out.println("<--数据已经保存了! -->");
System.out.println("<--是否继续录入?(Y/N)-->");
if (getConsoleInput().equalsIgnoreCase("N")) {
break;
}
}
release();
}catch (ClassNotFoundException e) {
e.printStaqckTrace();
}catch (SQLException e) {
e.printStackraqce();
}
System.exit (0); }private Valueobject getINfo() {
Valueobject vo = new Valueobject();
System.out.println("请录入学号: ");
vo.setNo(Integer.valueOf (getConsoluInput ()).intValue());
System.out.println("请录入姓名:");
vo.setName(getConsoleInput());
System.out. println("请录入性别(male/female): ");
vo.setSex(getConsoleInput());
System.out.println("请录入年龄: ");
vo.setAge(Integer.valueOf(getConsoleInput()).intValue());
return vo;
}
public void save(ValueObject vo) throws SQLException { pstmt = conn.createStatement();
pstmt
.executeUpdate(INSERT INTO Student(Sno,Sname,Ssex,Sage,Sdept)
VALUES ("
+ vo.getNo()
+ ",'"
+ vo.getName()
+ ",'"
+ vo.getSex()
+ ",'"
+ vo.getAge()
+ ",'"
+ vo.getDept() + "')");
}
private void release() throws SQLException {
if (pstmt != null) {
pstmt.close();
}
if (conn != null && !conn.isClosed()) {
conn.close();
}
}
private void getConnection() throws ClassNotFoundException, SQLException
{
Class.forName("sun.jdbc.odbc.JdbcodbcDriver");
conn = DriverManager.getConnection(strurl, null, null);
} public static void main(String[] args) { DBDemo demo = new DBDemo();
demo.run();
}
}
抛出unclosed string literal异常!在pstmt那里
import java.io.BufferedReader;
import java.io.IoException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;public class DBDemo {
private String strurl = "jdbc:odbc:book";
private connection conn = null;private Statement pstmt = null;private String getconsoleInput () {
String str = "";
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
try {
str = br.readLine();
} catch (IoException e) {
e.printStackTrace();
}
return str;
} public void ren() {
try {
getConnection();
while (true) {
System.out.println("<--请输入学生信息-->");
ValueObject vo = getInfo();
System.out.println("<--输入的学生信息如下-->");
System.out.println(vo);
System.out.println("<--正在保存数据,请稍候...-->");
save(vo);
System.out.println("<--数据已经保存了! -->");
System.out.println("<--是否继续录入?(Y/N)-->");
if (getConsoleInput().equalsIgnoreCase("N")) {
break;
}
}
release();
}catch (ClassNotFoundException e) {
e.printStaqckTrace();
}catch (SQLException e) {
e.printStackraqce();
}
System.exit (0); }private Valueobject getINfo() {
Valueobject vo = new Valueobject();
System.out.println("请录入学号: ");
vo.setNo(Integer.valueOf (getConsoluInput ()).intValue());
System.out.println("请录入姓名:");
vo.setName(getConsoleInput());
System.out. println("请录入性别(male/female): ");
vo.setSex(getConsoleInput());
System.out.println("请录入年龄: ");
vo.setAge(Integer.valueOf(getConsoleInput()).intValue());
return vo;
}
public void save(ValueObject vo) throws SQLException { pstmt = conn.createStatement();
pstmt
.executeUpdate(INSERT INTO Student(Sno,Sname,Ssex,Sage,Sdept)
VALUES ("
+ vo.getNo()
+ ",'"
+ vo.getName()
+ ",'"
+ vo.getSex()
+ ",'"
+ vo.getAge()
+ ",'"
+ vo.getDept() + "')");
}
private void release() throws SQLException {
if (pstmt != null) {
pstmt.close();
}
if (conn != null && !conn.isClosed()) {
conn.close();
}
}
private void getConnection() throws ClassNotFoundException, SQLException
{
Class.forName("sun.jdbc.odbc.JdbcodbcDriver");
conn = DriverManager.getConnection(strurl, null, null);
} public static void main(String[] args) { DBDemo demo = new DBDemo();
demo.run();
}
}
抛出unclosed string literal异常!在pstmt那里
真不知道你是怎么写程序的
DBDemo.java:71: ')' expected
.executeUpdate(INSERT INTO Student(Sno,Sname,Ssex,Sage,Sdept)
^
DBDemo.java:72: unclosed string literal
VALUES ("
^
2 errors
C:\myjava\数据库>javac DBDemo.java
DBDemo.java:70: unclosed string literal
pstmt.executeUpdate("INSERT INTO Student(Sno,Sname,Ssex,Sage,Sdept)
^
DBDemo.java:71: unclosed string literal
VALUES ("
^
DBDemo.java:80: ')' expected
+ vo.getDept() + "')");
^
3 errors
我把上面改成了
public void save(ValueObject vo) throws SQLException { pstmt = conn.createStatement();
pstmt.executeUpdate("INSERT INTO Student(Sno,Sname,Ssex,Sage,Sdept)
VALUES ("
+ vo.getNo()
+ ",'"
+ vo.getName()
+ ",'"
+ vo.getSex()
+ ",'"
+ vo.getAge()
+ ",'"
+ vo.getDept() + "')");
}