• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is a general error(java.sql.SQLException: General error)

 
D naik
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.sql.*;

public class PreDemo
{
public static void main(String args[])
{
Connection conn;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbcdbc:dsn");
PreparedStatement ps=conn.prepareStatement("insert into Emp values(?,?,?)");
ps.setInt(1,18);
ps.setInt(2,10);
ps.setString(3,"pps");

ps.executeUpdate();
Statement st = conn.createStatement();
ResultSet rs=st.executeQuery("select * from Emp");
ResultSetMetaData md=rs.getMetaData();
int col=md.getColumnCount();
int i=0;
System.out.print("Table name:"+md.getTableName(i)+"\t");

while(rs.next())
{
for(i=1;i<=col;i++)
System.out.print(rs.getString(1)+"\t");
System.out.print("\n");
}
}
catch(Exception e)
{
System.out.print(e);
}
}
}
 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

"General error" is a message which MS Access produces when it gets confused, which is quite often. It means that you did something which it didn't understand, and that it wasn't programmed to produce a useful error message.

In your case the error is probably because you're calling rs.getString(1) more than once for a row, which MS Access doesn't allow. Other databases do allow that, and produce better error messages, and are generally not as awful as MS Access. Hopefully you are only using Access for learning basic JDBC and don't plan to use it in real life with Java code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic