这是我写的程序,麻烦帮忙看下,怎么运行不了,在netbeans中是停止不前,在eclipse中是显示:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:
import java.sql.*;
public class Text { /**
* @param args
*/
public static void main(String[] args) {
String url="jdbc:mysql://127.0.0.1:3306/xyyc";
Connection conn;
Statement stmt;
ResultSet rs;
String name="xyyc";
String password="xyyc"; try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(url, "root", "root");
stmt=conn.createStatement();
String q="select password from user " +
"where "+"username= '"+name+
"' and password '"+password+"'";
rs=stmt.executeQuery(q);
if(rs.next()){
System.out.print("ok");
}
else{
System.out.print("false");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
import java.sql.*;
public class Text { /**
* @param args
*/
public static void main(String[] args) {
String url="jdbc:mysql://127.0.0.1:3306/xyyc";
Connection conn;
Statement stmt;
ResultSet rs;
String name="xyyc";
String password="xyyc"; try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(url, "root", "root");
stmt=conn.createStatement();
String q="select password from user " +
"where "+"username= '"+name+
"' and password '"+password+"'";
rs=stmt.executeQuery(q);
if(rs.next()){
System.out.print("ok");
}
else{
System.out.print("false");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
"where "+"username= '"+name+
"' and password '"+password+"'";
改成:
String q="select password from user " +
"where "+"username= '"+name+
"' and password ='"+password+"'";try it
将拼装好的SQL 输出到控制台 然后在SQL查询分析器中执行