AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem Java MySQL

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Whisky
Guest





PostPosted: Fri Nov 21, 2003 12:27 am    Post subject: Problem Java MySQL Reply with quote



I'm trying to connect a simple javaprogram to a MySQL-database.

Do someone have a codeexample of a working program thats does a simple
selectquery and then print the answer on the screen. Lets say it should
print the famous word - HelloWorld. It should be "from the beginning".

Thanks in advance.



Back to top
Christophe Vanfleteren
Guest





PostPosted: Fri Nov 21, 2003 12:37 am    Post subject: Re: Problem Java MySQL Reply with quote



Whisky wrote:

Quote:
I'm trying to connect a simple javaprogram to a MySQL-database.

Do someone have a codeexample of a working program thats does a simple
selectquery and then print the answer on the screen. Lets say it should
print the famous word - HelloWorld. It should be "from the beginning".

Thanks in advance.

http://java.sun.com/docs/books/tutorial/jdbc/

--
Regards,
Christophe Vanfleteren

Back to top
Tanel
Guest





PostPosted: Fri Nov 21, 2003 1:30 pm    Post subject: Re: Problem Java MySQL Reply with quote





Christophe Vanfleteren wrote:
Quote:
Whisky wrote:


I'm trying to connect a simple javaprogram to a MySQL-database.

Do someone have a codeexample of a working program thats does a simple
selectquery and then print the answer on the screen. Lets say it should
print the famous word - HelloWorld. It should be "from the beginning".

Thanks in advance.


http://java.sun.com/docs/books/tutorial/jdbc/


Check out
http://www.mysql.com/documentation/connector-j/index.html#id2801908


Back to top
Whisky
Guest





PostPosted: Fri Nov 21, 2003 7:36 pm    Post subject: Re: Problem Java MySQL Reply with quote

forgot to tell that it is on a stand-alone machine, dvs local host.
=)
/E
"Tanel" <tanel.lebedev (AT) d-codex (DOT) com> skrev i meddelandet
news:3fbe135e$1_1 (AT) news (DOT) estpak.ee...
Quote:


Christophe Vanfleteren wrote:
Whisky wrote:


I'm trying to connect a simple javaprogram to a MySQL-database.

Do someone have a codeexample of a working program thats does a simple
selectquery and then print the answer on the screen. Lets say it should
print the famous word - HelloWorld. It should be "from the beginning".

Thanks in advance.


http://java.sun.com/docs/books/tutorial/jdbc/


Check out
http://www.mysql.com/documentation/connector-j/index.html#id2801908




Back to top
nigel salt
Guest





PostPosted: Sat Nov 22, 2003 8:54 am    Post subject: Re: Problem Java MySQL Reply with quote

I think this is about as simple as it gets

public class jdbcTableDump {
public static void main(String args[]) {
String url = "jdbc:mysql://127.0.0.1:3306/nigel";
String query = "select * from comics";
String username="nigel";
String password="nigel";
Connection con=null;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, username, password);
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}

try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
// column names start at 1
for (int i=1;i<=numberOfColumns;i++) {
System.out.print(rsmd.getColumnName(i)+"t");
}
System.out.println("");

while (rs.next()) {
for (int i=1;i<=numberOfColumns;i++) {
System.out.print(rs.getString(i)+"t");
}
System.out.println("");
}
stmt.close();
con.close();

} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
"Whisky"
Quote:
I'm trying to connect a simple javaprogram to a MySQL-database.

Do someone have a codeexample of a working program thats does a simple
selectquery and then print the answer on the screen. Lets say it should
print the famous word - HelloWorld. It should be "from the beginning".

Thanks in advance.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.