Reputation: 111
DB and table names are correct. linked the classpath of MySQL connecter java. but when i run i get Not Found Result. i have tried different queries and different links to sql connector.
final static String jdbc_driver="com.mysql.jdbc.Driver";
final static String db_url="jdbc:mysql://localhost/oyutan/";
Connection con=null;
java.sql.PreparedStatement ps=null;
ResultSet rs=null;
@Override
public void actionPerformed(ActionEvent r) {
if(r.getSource()==ok){
fr.setVisible(false);
GUI guu=new GUI();
String card=cardnum.getText();
String pinn=pin.getText();
String sql="SELECT *FROM `card`";
try{
Class.forName(jdbc_driver);
con=DriverManager.getConnection(db_url, "root", "");
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next());{
System.out.println(rs.getString("")+"");
}}
catch(Exception e){
System.out.println("Not Found!");
}
}
}
Upvotes: 0
Views: 85
Reputation: 1
I think your sql was wrong.
String sql="SELECT * FROM card ";
you need add a white space after " * "
Upvotes: 0
Reputation: 7
You made a mistake you must add the portnumber after localhost. in db_url
ex :- final static String db_url="jdbc:mysql://localhost/oyutan/";
modify this as
final static String db_url="jdbc:mysql://localhost:<port number>/oyutan/";
without the port number it wont work. the port number is not always the same it could be 3306,3309 etc..
final static String db_url="jdbc:mysql://localhost:3306/oyutan/";
Upvotes: 0
Reputation: 4252
There is no space between * And FROM , try using this :
String sql = "SELECT * FROM 'card' ";
Upvotes: 0
Reputation: 3386
change
String sql="SELECT *FROM `card`";
to
String sql="SELECT * FROM card ";
and give a try
Upvotes: 1