Help with java and sql
- From: "debbienc" <debbienc@xxxxxxx>
- Date: 1 Dec 2006 20:22:54 -0800
Can someone please help me? I am getting the error message:
[MySQL][ODBC 3.51 Driver][mysqld-5.0.24a-community-nt]No database
selected
When I open up (control panel) (administrative tools) (ODBC) and click
on plantco, then configure and then test, it says success connection
was made, but when I open command prompt and put in C:
cd\
cd j2sdk1.4.2_12\testprog
javac EXO.java
java EXO data2
I get the above error message
This is what I have put in notepad:
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class EXO {
public static void main (String [ ] args ) {
String recordInput=" ";
String sqlCommand= " ";
try {
String url="jdbc:odbc:plantco";
String user="root"; // The user name
String password=""; // The password
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection(url,
user, password);
Statement
sttmnt=conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String filename="";
if (args.length > 0)
{
filename = args [0];//Filename
}
else
{
System.out.println("Must supply a file name!");
System.exit(0);
}
BufferedReader inputFile=new BufferedReader
(new FileReader(filename + ".txt"));
sttmnt.executeUpdate("DROP TABLE WinesList");
recordInput=inputFile.readLine();// Read 1st record
sqlCommand="CREATE TABLE WinesList " + recordInput;
//Create SQL statement
sttmnt.executeUpdate(sqlCommand);
//Execute SQL statement
while ((recordInput = inputFile.readLine()) != null)
{
sqlCommand = "INSERT INTO WinesList (Name_wine," +
" on_hand, " + "Color_wine, Cost)";
sqlCommand += "values (" + recordInput + ")";
sttmnt.executeUpdate (sqlCommand); //Execute SQL
System.out.println(sqlCommand);
} // end of while
sttmnt.close();// Close the Statement object
} // end of try
catch ( SQLException s) {// Process SQLException
JOptionPane.showMessageDialog(null, s.getMessage(),
"Database error",
JOptionPane.ERROR_MESSAGE );
System.exit(0);
} // end of catch
catch ( Exception e) {//All other exceptions
JOptionPane.showMessageDialog(null,
e.getMessage( ),
"Driver not found error",
JOptionPane.ERROR_MESSAGE );
System.exit(0);
} //end of catch
} //end of main
} //end of class
Can someone please help me. I have tried everything I can think of,
and looked at several totorials, but I cannot find anything to help me.
Thanks,
Debbie
.
- Follow-Ups:
- Re: Help with java and sql
- From: Arne Vajhøj
- Re: Help with java and sql
- From: Jeff
- Re: Help with java and sql
- Prev by Date: Re: select performance
- Next by Date: Re: Help with java and sql
- Previous by thread: Re: select performance
- Next by thread: Re: Help with java and sql
- Index(es):
Relevant Pages
|
|