java 连接Mysql问题?帮忙看看,谢谢啦! jdbc:mysql://localhost/tb1_user?user=root&password=onlywh&useUnicode=true&characterEncoding=GB2312这个url的作用就是连接数据库的,不过只是把user和password加进去而已 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 mysql默认的端口是3306,你修改了端口成为80端口?不会吧! 我没有修改什么端口啊!就默认安装的。例外表的位置怎么指定啊?就在URL里面写上表名就可以了?不用管他存放在什么地方吗?jdbc:mysql://localhost/tb1_user?user=root&password=onlywh&useUnicode=true&characterEncoding=GB2312 jdbc:mysql://localhost/tb1_user?user=root&password=onlywh&useUnicode=true&characterEncoding=GB2312表名不就是tb1_user吗?不用管他放在什么地方,会自动连接到数据库的服务器上 import java.sql.Connection;import java.sql.DriverManager; import java.sql.SQLException; public class MysqlConnection{ public static void main(String[] args){ try{ Class.forName("com.mysql.jdbc.Driver"); System.out.println("Success loading Mysql Driver!"); } catch(Exception e){ System.out.println("Error loading Mysql Driver!"); e.printStackTrace(); } }} 执行这一段代码显示出Success loading Mysql Driver!是不是就表示出能够正常加载驱动了? 另外我把mysql-connector-java-3.1.7-bin放在了D:\Sun\Java\jdk1.5.0_01\jre\lib\ext,然后执行这个代码import java.sql.Connection;import java.sql.DriverManager; import java.sql.SQLException; public class MysqlConnection{ public static void main(String[] args){ try{ Class.forName("com.mysql.jdbc.Driver"); System.out.println("Success loading Mysql Driver!"); } catch(Exception e){ System.out.println("Error loading Mysql Driver!"); e.printStackTrace(); } }} 显示出Success loading Mysql Driver!就表示加载成功了把?不用在配置什么JDBC 了吧? 不用了,加载没问题了试下连接import java.sql.Connection;import java.sql.DriverManager; import java.sql.SQLException; public class MysqlConnection{ public static void main(String[] args){ try{ Class.forName("com.mysql.jdbc.Driver"); String url ="jdbc:mysql://localhost/test?user=root&password=onlywh&useUnicode=true&characterEncoding=8859_1" //myDB为数据库名 Connection conn= DriverManager.getConnection(url); System.out.println("连接成功!"); } catch(Exception e){ System.out.println("Error loading Mysql Driver!"); e.printStackTrace(); } }} test是mysql一定有的数据库,连接看看 Success loading Mysql Driver既然提示这句,就表示已经连接成功了,再你可以随便去操纵它了!! 问题解决啦~test是数据库名,我以为是表名,晕,="jdbc:mysql://localhost/test?user=root&password=onlywh&useUnicode=true&characterEncoding=8859_1"谢谢大家! 使用input.nextLine()结果输入时跳过了,想不通 if条件句中关于else if的问题 文件在写入后读取为乱码问题 Socket 急!vector的问题 java.lang.NullPointerException JComboBox无法动态改变 想用java做图像处理(JPEG2000),主要应该侧重java的哪方面学习? HTTP服务器的模拟程序:怎么判断客户机传送过来的数据已经完毕啊?? 一个FTPServer相关的问题, 关于synchronized方法的探讨 谢谢帮我看看,怎么解决这个问题 netbeans4.0的中文问题
例外表的位置怎么指定啊?就在URL里面写上表名就可以了?不用管他存放在什么地方吗?
jdbc:mysql://localhost/tb1_user?user=root&password=onlywh&useUnicode=true&characterEncoding=GB2312
import java.sql.DriverManager;
import java.sql.SQLException; public class MysqlConnection{
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Success loading Mysql Driver!");
}
catch(Exception e){
System.out.println("Error loading Mysql Driver!");
e.printStackTrace();
}
}
}
执行这一段代码显示出Success loading Mysql Driver!
是不是就表示出能够正常加载驱动了?
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException; public class MysqlConnection{
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Success loading Mysql Driver!");
}
catch(Exception e){
System.out.println("Error loading Mysql Driver!");
e.printStackTrace();
}
}
}
显示出Success loading Mysql Driver!
就表示加载成功了把?不用在配置什么JDBC 了吧?
试下连接
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException; public class MysqlConnection{
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
String url ="jdbc:mysql://localhost/test?user=root&password=onlywh&useUnicode=true&characterEncoding=8859_1"
//myDB为数据库名
Connection conn= DriverManager.getConnection(url); System.out.println("连接成功!");
}
catch(Exception e){
System.out.println("Error loading Mysql Driver!");
e.printStackTrace();
}
}
}
="jdbc:mysql://localhost/test?user=root&password=onlywh&useUnicode=true&characterEncoding=8859_1"谢谢大家!